html.tmbundle icon indicating copy to clipboard operation
html.tmbundle copied to clipboard

Embedded JavaScript grammar can break the colorization

Open aeschli opened this issue 6 years ago • 7 comments

The following code doesn't highlight correctly in VSCode after //</script>. The problem is that the embedded JavaScript grammar consumes the full //</script> and the sourrounding html rule doesn't end. The grammar is stuck in js.

<!DOCTYPE html>
<html>
<head>
    <script>
        //</script>
</head>
<body>

</body>
</html>

There are many similar issues when the JS code is not complete and the JavaScript grammar is in the middle of some rule.

IMO the best thing would be to not include the full blown JavaScript grammar but embed a (simplified) variant that is aware of the </script> tag

aeschli avatar Jun 01 '18 07:06 aeschli

Hi @aeschli, do you know by any chance if this issue occurs with other applications besides VSCode which uses this html.tmbundle TextMate grammar?

SDP190 avatar Jun 01 '18 15:06 SDP190

This is a rehash of #72, will leave this open for the moment as it might be good to look at the non-comment issues. Will post more about the comment problem in Microsoft/vscode-textmate#49.

infininight avatar Jun 01 '18 22:06 infininight

This would reproduce in any editor using TM bundles if the exact same grammars are used for HTML and JavaScript.

alexdima avatar Jun 11 '18 15:06 alexdima

@infininight, @aeschli, @alexandrudima

I think this issue can be corrected per my comment in Microsoft/vscode-textmate#49. https://github.com/Microsoft/vscode-textmate/issues/49#issuecomment-423029694

Looks like its about line 2937 in the PLIST file.

This was pretty easy to trace down using vscode-textmate's INSPECT after I modified 'Grammar.ts' to enable the debug output of which expressions were being attempted. That should be made an option of say 'INSPECTDEEP' or something. :)

msftrncs avatar Sep 20 '18 03:09 msftrncs

@msftrncs Replied in other thread.

infininight avatar Sep 20 '18 09:09 infininight

IMO the best thing would be to not include the full blown JavaScript grammar but embed a (simplified) variant that is aware of the </script> tag

@aeschli Do you have any tips on how you might recommend going about this? Are you talking about literally rewriting or copying a subset of the JavaScript grammar and inserting recognition of the end condition, or is there some shortcut or more efficient way to do this, like including specific repositories from an external grammar? I've tried doing things like this (in this example to embed the relevant portion of the CSS grammar into an HTML style attribute), but without any luck:

"patterns": [
  { "include": "source.css#rule-list" }
]

Is there a correct way to do that and I'm just doing it wrong, or is it just not possible? The documentation on embedded grammars is pretty sparse.

dannymcgee avatar Jan 18 '20 03:01 dannymcgee

Are you talking about literally rewriting or copying a subset of the JavaScript grammar and inserting recognition of the end condition

That's what I meant. The idea would be to simplify it, maybe just keywords, comments and literals. That means duplication of some rules, but gives full control and avoids dependencies

aeschli avatar Jan 21 '20 08:01 aeschli