Skip to content

Commit

Permalink
[html] issues caused by HTML grammar associating '<' with JS. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Dec 20, 2019
1 parent c97c457 commit 18bab62
Show file tree
Hide file tree
Showing 10 changed files with 1,072 additions and 18 deletions.
44 changes: 44 additions & 0 deletions extensions/html/build/update-grammar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// @ts-check
'use strict';

var updateGrammar = require('../../../build/npm/update-grammar');

function patchGrammar(grammar) {
let patchCount = 0;

let visit = function (rule, parent) {
if (rule.name === 'source.js' || rule.name === 'source.css') {
if (parent.parent && parent.parent.property === 'endCaptures') {
rule.name = rule.name + '-ignored-vscode';
patchCount++;
}
}
for (let property in rule) {
let value = rule[property];
if (typeof value === 'object') {
visit(value, { node: rule, property: property, parent: parent });
}
}
};

let repository = grammar.repository;
for (let key in repository) {
visit(repository[key], { node: repository, property: key, parent: undefined });
}
if (patchCount !== 6) {
console.warn(`Expected to patch 6 occurrences of source.js & source.css: Was ${patchCount}`);
}


return grammar;
}

const tsGrammarRepo = 'textmate/html.tmbundle';
const grammarPath = 'Syntaxes/HTML.plist';
updateGrammar.update(tsGrammarRepo, grammarPath, './syntaxes/html.tmLanguage.json', grammar => patchGrammar(grammar));


2 changes: 1 addition & 1 deletion extensions/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"vscode": "0.10.x"
},
"scripts": {
"update-grammar": "node ../../build/npm/update-grammar.js textmate/html.tmbundle Syntaxes/HTML.plist ./syntaxes/html.tmLanguage.json Syntaxes/HTML%20%28Derivative%29.tmLanguage ./syntaxes/html-derivative.tmLanguage.json"
"update-grammar": "node ./build/update-grammar.js"
},
"contributes": {
"languages": [
Expand Down
12 changes: 6 additions & 6 deletions extensions/html/syntaxes/html.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"name": "punctuation.definition.string.end.html"
},
"1": {
"name": "source.css"
"name": "source.css-ignored-vscode"
}
},
"name": "string.quoted.double.html",
Expand All @@ -132,7 +132,7 @@
"name": "punctuation.definition.string.end.html"
},
"1": {
"name": "source.css"
"name": "source.css-ignored-vscode"
}
},
"name": "string.quoted.single.html",
Expand Down Expand Up @@ -207,7 +207,7 @@
"name": "punctuation.definition.string.end.html"
},
"1": {
"name": "source.js"
"name": "source.js-ignored-vscode"
}
},
"name": "string.quoted.double.html",
Expand Down Expand Up @@ -265,7 +265,7 @@
"name": "punctuation.definition.string.end.html"
},
"1": {
"name": "source.js"
"name": "source.js-ignored-vscode"
}
},
"name": "string.quoted.single.html",
Expand Down Expand Up @@ -1785,7 +1785,7 @@
"name": "punctuation.definition.tag.begin.html"
},
"2": {
"name": "source.css"
"name": "source.css-ignored-vscode"
},
"3": {
"name": "entity.name.tag.html"
Expand Down Expand Up @@ -1892,7 +1892,7 @@
"name": "punctuation.definition.tag.begin.html"
},
"2": {
"name": "source.js"
"name": "source.js-ignored-vscode"
}
},
"patterns": [
Expand Down
6 changes: 6 additions & 0 deletions extensions/html/test/colorize-fixtures/test-embedding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>console.log('x')</script>
<style>test { display: none }</style>
<a onblur="doBlur()" onclick='doClick()' ondrag=doDrag()></a>
<div style="x { }"></div>
<div style='y { }'></div>
<div style=z{}></div>
4 changes: 2 additions & 2 deletions extensions/html/test/colorize-results/12750_html.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
},
{
"c": "<",
"t": "text.html.derivative meta.embedded.block.html meta.tag.metadata.script.end.html punctuation.definition.tag.begin.html source.js",
"t": "text.html.derivative meta.embedded.block.html meta.tag.metadata.script.end.html punctuation.definition.tag.begin.html source.js-ignored-vscode",
"r": {
"dark_plus": "punctuation.definition.tag: #808080",
"light_plus": "punctuation.definition.tag: #800000",
Expand Down Expand Up @@ -397,7 +397,7 @@
},
{
"c": "<",
"t": "text.html.derivative meta.embedded.block.html meta.tag.metadata.script.end.html punctuation.definition.tag.begin.html source.js",
"t": "text.html.derivative meta.embedded.block.html meta.tag.metadata.script.end.html punctuation.definition.tag.begin.html source.js-ignored-vscode",
"r": {
"dark_plus": "punctuation.definition.tag: #808080",
"light_plus": "punctuation.definition.tag: #800000",
Expand Down
2 changes: 1 addition & 1 deletion extensions/html/test/colorize-results/25920_html.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
},
{
"c": "<",
"t": "text.html.derivative meta.embedded.block.html meta.tag.metadata.script.end.html punctuation.definition.tag.begin.html source.js",
"t": "text.html.derivative meta.embedded.block.html meta.tag.metadata.script.end.html punctuation.definition.tag.begin.html source.js-ignored-vscode",
"r": {
"dark_plus": "punctuation.definition.tag: #808080",
"light_plus": "punctuation.definition.tag: #800000",
Expand Down
Loading

0 comments on commit 18bab62

Please sign in to comment.