Pretty Self-Closing Tags

Issue: #149
This commit is contained in:
Josh Johnson 2018-05-29 21:56:29 -04:00
parent 07b47c4748
commit 156e1ab435
5 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -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),