forked from external/vscode-xml
Implemented conversion from XML to text and viceversa
This commit is contained in:
parent
84adff578f
commit
51b6b4fbaa
7 changed files with 70 additions and 2 deletions
|
|
@ -1,2 +1,4 @@
|
|||
export * from "./formatAsXml";
|
||||
export * from "./minifyXml";
|
||||
export * from "./xmlToText";
|
||||
export * from "./textToXml";
|
||||
|
|
|
|||
26
src/formatting/commands/textToXml.ts
Normal file
26
src/formatting/commands/textToXml.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { workspace } from "vscode";
|
||||
import { ProviderResult, Range, TextEdit, editor, editorEdit, Selection } from "vscode";
|
||||
|
||||
import { NativeCommands } from "../../common";
|
||||
import * as constants from "../../constants";
|
||||
|
||||
import { XmlFormatterFactory } from "../xml-formatter";
|
||||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||
|
||||
export function textToXml(editor: editor, edit: editorEdit): void {
|
||||
editor.edit(edit => {
|
||||
let selections = editor.selections;
|
||||
selections.forEach(selection => {
|
||||
if (selection.isEmpty) {
|
||||
selection = new Selection(
|
||||
editor.document.positionAt(0),
|
||||
editor.document.positionAt(editor.document.getText().length)
|
||||
);
|
||||
}
|
||||
let txt = editor.document.getText(new Range(selection.start, selection.end));
|
||||
let transformed = txt.replace(/</g, '<').replace(/>/g, '>');
|
||||
edit.replace(selection, transformed);
|
||||
});
|
||||
});
|
||||
}
|
||||
26
src/formatting/commands/xmlToText.ts
Normal file
26
src/formatting/commands/xmlToText.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { workspace } from "vscode";
|
||||
import { ProviderResult, Range, TextEdit, editor, editorEdit, Selection } from "vscode";
|
||||
|
||||
import { NativeCommands } from "../../common";
|
||||
import * as constants from "../../constants";
|
||||
|
||||
import { XmlFormatterFactory } from "../xml-formatter";
|
||||
import { XmlFormattingEditProvider } from "../xml-formatting-edit-provider";
|
||||
import { XmlFormattingOptionsFactory } from "../xml-formatting-options";
|
||||
|
||||
export function xmlToText(editor: editor, edit: editorEdit): void {
|
||||
editor.edit(edit => {
|
||||
let selections = editor.selections;
|
||||
selections.forEach(selection => {
|
||||
if (selection.isEmpty) {
|
||||
selection = new Selection(
|
||||
editor.document.positionAt(0),
|
||||
editor.document.positionAt(editor.document.getText().length)
|
||||
);
|
||||
}
|
||||
let txt = editor.document.getText(new Range(selection.start, selection.end));
|
||||
let transformed = txt.replace(/</g, '<').replace(/>/g, '>');
|
||||
edit.replace(selection, transformed);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue