DotJoshJohnson / vscode-xml

XML Tools for Visual Studio Code
MIT License
320 stars 87 forks source link

XML Tools: Convert XML to text (<> -> &lt;&gt;) not equals XML Tools: Convert XML to text (<> -> &amp;lt;&amp;gt;) #374

Open AShchelygin opened 2 years ago

AShchelygin commented 2 years ago

Description

Convert XML to text does not work as advertised. Fact result: <> -> &amp;lt;&amp;gt; Expected Result: <> -> &lt;&gt;

Formatter Implementation

classic

XML Tools Version

v2.5.1

VS Code Version

1.63.2

Operating System

Windows 7 x64 Pro

AShchelygin commented 2 years ago

FIX: .vscode\extensions\dotjoshjohnson.xml-2.5.1\out\formatting\commands\xmlToText.js

Move .replace(/&/g, "&amp;") to 13 line (& must be first)

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const vscode_1 = require("vscode");
function xmlToText(textEditor) {
    textEditor.edit(textEdit => {
        const selections = textEditor.selections;
        selections.forEach(selection => {
            if (selection.isEmpty) {
                selection = new vscode_1.Selection(textEditor.document.positionAt(0), textEditor.document.positionAt(textEditor.document.getText().length));
            }
            const txt = textEditor.document.getText(new vscode_1.Range(selection.start, selection.end));
            const transformed = txt
                .replace(/&/g, "&amp;")
                .replace(/</g, "&lt;")
                .replace(/>/g, "&gt;")
                .replace(/"/g, "&quot;")
                .replace(/'/g, "&apos;");
            textEdit.replace(selection, transformed);
        });
    });
}
exports.xmlToText = xmlToText;
//# sourceMappingURL=xmlToText.js.map