parent
07b47c4748
commit
156e1ab435
@ -86,6 +86,12 @@
|
||||
"description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.",
|
||||
"scope": "window"
|
||||
},
|
||||
"xmlTools.enforcePrettySelfClosingTagOnFormat": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Enforces a space before the forward slash at the end of a self-closing XML tag.",
|
||||
"scope": "resource"
|
||||
},
|
||||
"xmlTools.ignoreDefaultNamespace": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
|
@ -43,6 +43,10 @@ export class Configuration {
|
||||
return this._getForWindow<string>("xqueryExecutionInputSearchPattern");
|
||||
}
|
||||
|
||||
static enforcePrettySelfClosingTagOnFormat(resource: Uri): boolean {
|
||||
return this._getForResource<boolean>("enforcePrettySelfClosingTagOnFormat", resource);
|
||||
}
|
||||
|
||||
static removeCommentsOnMinify(resource: Uri): boolean {
|
||||
return this._getForResource<boolean>("removeCommentsOnMinify", resource);
|
||||
}
|
||||
|
@ -135,6 +135,14 @@ export class V2XmlFormatter implements XmlFormatter {
|
||||
location = Location.StartTag;
|
||||
}
|
||||
|
||||
// approaching the end of a self-closing tag where there was no whitespace (issue #149)
|
||||
else if ((location === Location.StartTag || location === Location.StartTagName)
|
||||
&& cc === "/"
|
||||
&& pc !== " "
|
||||
&& options.enforcePrettySelfClosingTagOnFormat) {
|
||||
output += " /";
|
||||
}
|
||||
|
||||
// exiting StartTag or StartTag.StartTagName, entering Text
|
||||
else if ((location === Location.StartTag || location === Location.StartTagName) && cc === ">") {
|
||||
// if this was a self-closing tag, we need to decrement the indent level and add a newLine
|
||||
|
@ -5,6 +5,7 @@ import * as constants from "../constants";
|
||||
|
||||
export interface XmlFormattingOptions {
|
||||
editorOptions: FormattingOptions;
|
||||
enforcePrettySelfClosingTagOnFormat: boolean;
|
||||
newLine: string;
|
||||
removeCommentsOnMinify: boolean;
|
||||
splitAttributesOnFormat: boolean;
|
||||
@ -15,6 +16,7 @@ export class XmlFormattingOptionsFactory {
|
||||
static getXmlFormattingOptions(formattingOptions: FormattingOptions, document: TextDocument): XmlFormattingOptions {
|
||||
return {
|
||||
editorOptions: formattingOptions,
|
||||
enforcePrettySelfClosingTagOnFormat: Configuration.enforcePrettySelfClosingTagOnFormat(document.uri),
|
||||
newLine: (document.eol === EndOfLine.CRLF) ? "\r\n" : "\n",
|
||||
removeCommentsOnMinify: Configuration.removeCommentsOnMinify(document.uri),
|
||||
splitAttributesOnFormat: Configuration.splitAttributesOnFormat(document.uri),
|
||||
|
@ -17,6 +17,7 @@ describe("V2XmlFormatter", () => {
|
||||
insertSpaces: true,
|
||||
tabSize: 4
|
||||
},
|
||||
enforcePrettySelfClosingTagOnFormat: false,
|
||||
newLine: "\r\n",
|
||||
removeCommentsOnMinify: false,
|
||||
splitAttributesOnFormat: false,
|
||||
@ -60,7 +61,11 @@ describe("V2XmlFormatter", () => {
|
||||
});
|
||||
|
||||
it("should allow users to enforce space before self-closing tag slash", () => {
|
||||
options.enforcePrettySelfClosingTagOnFormat = true;
|
||||
|
||||
testFormatter(xmlFormatter, options, "issue-149");
|
||||
|
||||
options.enforcePrettySelfClosingTagOnFormat = false;
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user