Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTML] Fix scopes of stray script and style tags #3032

Merged

Conversation

deathaxe
Copy link
Collaborator

@deathaxe deathaxe commented Sep 9, 2021

This PR...

  1. fixes scopes of stray script and style tags, which didn't match those from tag pairs.

  2. avoids multi-pushing into embedded script/style syntaxes to simplify the language a bit and improve parsing performance. Closing tags are consumed within main context now.

  3. removes pushing text.html.embedded.html onto stack.

    a) As main context is pushed, it is not required for highlighting.
    b) The only thing we loose is the mentioned scope, which seems to be of little value.
    c) It is required as change (2) would break boundaries of text.html.embedded otherwise.
    d) The less contexts HTML pushes onto stack the better it is for most possible flexibility with regards to inheritance or re-use in
    heavily context aware templating syntaxes such as JSP or PHP.
    e) It slightly improves parsing performance.

  4. New script-tag and style-tag contexts are introduced to form a kind of template which can be used by inheriting syntaxes for other custom tags.

Notes:

  1. script-close-tag still exists, so existing syntaxes shouldn't break by this change.

  2. ASP syntax is adjusted to use the same strategy, but that's just to keep inline. It would have worked without that change, too.

This PR is inspired by vuejs/vue-syntax-highlight#216

This commit ...

1. fixes scopes of stray script and style tags, which didn't match
   those from tag pairs.

2. avoids multi-pushing into embedded script/style syntaxes to simplify
   the language a bit and improve parsing performance. Closing tags are
   consumed within `main` context now.

3. removes pushing `text.html.embedded.html` onto stack.

   a) As `main` context is pushed, it is not required for highlighting.
   b) The only thing we loose is the mentioned scope, which seems to be
      of little value.
   c) It is required as change (2) would break boundaries of
      `text.html.embedded` otherwise.
   d) The less contexts HTML pushes onto stack the better it is for most
      possible flexibility with regards to inheritance or re-use in
      heavily context aware templating syntaxes such as JSP or PHP.
   e) It slightly improves parsing performance.

4. New `script-tag` and `style-tag` contexts are introduced to form a
   kind of template which can be used by inheriting syntaxes for other
   custom tags.

Notes: 

1. `script-close-tag` still exists, so existing syntaxes shouldn't
    break by this change.

2.  ASP syntax is adjusted to use the same strategy, but that's just
    to keep inline. It would have worked without that change, too.
@jfcherng jfcherng merged commit 5288542 into sublimehq:master Sep 9, 2021
@deathaxe deathaxe deleted the pr/html/fix-stray-style-script-tags branch September 10, 2021 17:55
mitranim pushed a commit to mitranim/Packages that referenced this pull request Mar 25, 2022
This commit ...

1. fixes scopes of stray script and style tags, which didn't match
   those from tag pairs.

2. avoids multi-pushing into embedded script/style syntaxes to simplify
   the language a bit and improve parsing performance. Closing tags are
   consumed within `main` context now.

3. removes pushing `text.html.embedded.html` onto stack.

   a) As `main` context is pushed, it is not required for highlighting.
   b) The only thing we loose is the mentioned scope, which seems to be
      of little value.
   c) It is required as change (2) would break boundaries of
      `text.html.embedded` otherwise.
   d) The less contexts HTML pushes onto stack the better it is for most
      possible flexibility with regards to inheritance or re-use in
      heavily context aware templating syntaxes such as JSP or PHP.
   e) It slightly improves parsing performance.

4. New `script-tag` and `style-tag` contexts are introduced to form a
   kind of template which can be used by inheriting syntaxes for other
   custom tags.

Notes: 

1. `script-close-tag` still exists, so existing syntaxes shouldn't
    break by this change.

2.  ASP syntax is adjusted to use the same strategy, but that's just
    to keep inline. It would have worked without that change, too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants