mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
html: observe insertFinalNewline (#152446)
This commit is contained in:
committed by
GitHub
parent
223ea2c4b5
commit
630809a1ea
@@ -119,12 +119,6 @@
|
||||
"default": false,
|
||||
"markdownDescription": "%html.format.indentHandlebars.desc%"
|
||||
},
|
||||
"html.format.endWithNewline": {
|
||||
"type": "boolean",
|
||||
"scope": "resource",
|
||||
"default": false,
|
||||
"description": "%html.format.endWithNewline.desc%"
|
||||
},
|
||||
"html.format.extraLiners": {
|
||||
"type": [
|
||||
"string",
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
"html.format.preserveNewLines.desc": "Controls whether existing line breaks before elements should be preserved. Only works before elements, not inside tags or for text.",
|
||||
"html.format.maxPreserveNewLines.desc": "Maximum number of line breaks to be preserved in one chunk. Use `null` for unlimited.",
|
||||
"html.format.indentHandlebars.desc": "Format and indent `{{#foo}}` and `{{/foo}}`.",
|
||||
"html.format.endWithNewline.desc": "End with a newline.",
|
||||
"html.format.extraLiners.desc": "List of tags, comma separated, that should have an extra newline before them. `null` defaults to `\"head, body, /html\"`.",
|
||||
"html.format.wrapAttributes.desc": "Wrap attributes.",
|
||||
"html.format.wrapAttributes.auto": "Wrap attributes only when line length is exceeded.",
|
||||
|
||||
@@ -49,6 +49,9 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
|
||||
} else {
|
||||
formatSettings.contentUnformatted = 'script';
|
||||
}
|
||||
if (formatParams.insertFinalNewline) {
|
||||
formatSettings.endWithNewline = true;
|
||||
}
|
||||
merge(formatParams, formatSettings);
|
||||
return htmlLanguageService.format(document, range, formatSettings);
|
||||
},
|
||||
|
||||
@@ -85,16 +85,12 @@ suite('HTML Embedded Formatting', () => {
|
||||
});
|
||||
|
||||
test('EndWithNewline', async () => {
|
||||
const options = {
|
||||
html: {
|
||||
format: {
|
||||
endWithNewline: true
|
||||
}
|
||||
}
|
||||
};
|
||||
await assertFormat('<html><body><p>Hello</p></body></html>', '<html>\n\n<body>\n <p>Hello</p>\n</body>\n\n</html>\n', options);
|
||||
await assertFormat('<html>|<body><p>Hello</p></body>|</html>', '<html><body>\n <p>Hello</p>\n</body></html>', options);
|
||||
await assertFormat('<html><head><script>\nvar x=1;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n </script>\n</head>\n\n</html>\n', options);
|
||||
const options : FormattingOptions = FormattingOptions.create(2, true);
|
||||
options.insertFinalNewline = true;
|
||||
|
||||
await assertFormat('<html><body><p>Hello</p></body></html>', '<html>\n\n<body>\n <p>Hello</p>\n</body>\n\n</html>\n', {}, options);
|
||||
await assertFormat('<html>|<body><p>Hello</p></body>|</html>', '<html><body>\n <p>Hello</p>\n</body></html>', {}, options);
|
||||
await assertFormat('<html><head><script>\nvar x=1;\n</script></head></html>', '<html>\n\n<head>\n <script>\n var x = 1;\n </script>\n</head>\n\n</html>\n', {}, options);
|
||||
});
|
||||
|
||||
test('Inside script', async () => {
|
||||
|
||||
Reference in New Issue
Block a user