mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
[html] filter empty lines in virtual documents
This commit is contained in:
@@ -44,12 +44,28 @@ export function getEmbeddedContent(languageService: LanguageService, document: T
|
||||
}
|
||||
|
||||
function substituteWithWhitespace(result, start, end, oldContent) {
|
||||
let accumulatedWS = 0;
|
||||
for (let i = start; i < end; i++) {
|
||||
let ch = oldContent[i];
|
||||
if (ch !== '\n' && ch !== '\r') {
|
||||
ch = ' ';
|
||||
if (ch === '\n' || ch === '\r') {
|
||||
// only write new lines, skip the whitespace
|
||||
accumulatedWS = 0;
|
||||
result += ch;
|
||||
} else {
|
||||
accumulatedWS++;
|
||||
}
|
||||
result += ch;
|
||||
}
|
||||
result = append(result, ' ', accumulatedWS);
|
||||
return result;
|
||||
}
|
||||
|
||||
function append(result: string, str: string, n: number): string {
|
||||
while (n) {
|
||||
if (n & 1) {
|
||||
result += str;
|
||||
}
|
||||
n >>= 1;
|
||||
str += str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ suite('HTML Embedded Support', () => {
|
||||
assertEmbeddedLanguageContent('<html><style>foo { }</style></html>', 'css', ' foo { } ');
|
||||
assertEmbeddedLanguageContent('<html><script>var i = 0;</script></html>', 'css', ' ');
|
||||
assertEmbeddedLanguageContent('<html><style>foo { }</style>Hello<style>foo { }</style></html>', 'css', ' foo { } foo { } ');
|
||||
assertEmbeddedLanguageContent('<html>\n <style>\n foo { } \n </style>\n</html>\n', 'css', '\n \n foo { } \n \n\n');
|
||||
|
||||
});
|
||||
|
||||
test('Scripts', function (): any {
|
||||
|
||||
Reference in New Issue
Block a user