From a67f6f8d835250971ba89fd64906143ac6ace9d5 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 2 Jul 2020 00:09:46 -0400 Subject: [PATCH] Add &, ", and ' Entities fixes #271 --- src/formatting/commands/textToXml.ts | 8 +++++++- src/formatting/commands/xmlToText.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/formatting/commands/textToXml.ts b/src/formatting/commands/textToXml.ts index de2884f..0b9dec0 100644 --- a/src/formatting/commands/textToXml.ts +++ b/src/formatting/commands/textToXml.ts @@ -19,7 +19,13 @@ export function textToXml(textEditor: TextEditor): void { ); } const txt = textEditor.document.getText(new Range(selection.start, selection.end)); - const transformed = txt.replace(/</g, "<").replace(/>/g, ">"); + const transformed = txt + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/&/g, "&") + .replace(/"/g, '"') + .replace(/'/g, "'"); + textEdit.replace(selection, transformed); }); }); diff --git a/src/formatting/commands/xmlToText.ts b/src/formatting/commands/xmlToText.ts index f3d63ac..5dea03f 100644 --- a/src/formatting/commands/xmlToText.ts +++ b/src/formatting/commands/xmlToText.ts @@ -19,7 +19,13 @@ export function xmlToText(textEditor: TextEditor): void { ); } const txt = textEditor.document.getText(new Range(selection.start, selection.end)); - const transformed = txt.replace(//g, ">"); + const transformed = txt + .replace(//g, ">") + .replace(/&/g, "&") + .replace(/"/g, """) + .replace(/'/g, "'"); + textEdit.replace(selection, transformed); }); });