zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
103 stars 14 forks source link

Cannot get nested HTML folding to work within a data script element #33

Closed TotallyInformation closed 3 years ago

TotallyInformation commented 3 years ago

Describe the bug

When editing HTML using VScode's auto folding. Nested html elements do not seem to fold when they are inside a <script> element. I've already used this extension to add JSDoc folding to javascript files but I cannot find a setting that lets me fold nested html elements inside the script element.

image

Note how folding works OK for the nested para elements but not inside script.

To reproduce

Code Example

<script type="text/html" data-help-name="uibuilder">
    <p>Easily create a data-driven web user interface (UI)</p>
    <p>
        Create dynamic, data-driven user interfaces that send and receive messages to/from Node-RED.
        Creates a file/folder structure that is used to deliver static resources (html, css, js, images, etc) and
        manages the delivery of vendor library resources (VueJS, jQuery, etc).
        You can also pass script and style information to the front-end in a message.
    </p>
</script>

Settings

"folding": {
  "html": {
    "begin": "<",
    "end": "</",
  }
}

OR

"folding": {
  "html": {
    "beginRegex": "\\<.*\\>",
    "endRegex": "\\</.*\\>"
  }
}

Note, however, that the following DOES work, but obviously only for the para element, not for anything else:

"folding": {
  "html": {
    "begin": "<p",
    "end": "</p",
  }
}

Expected behavior

Folding should occur within an outer <script> element

Screenshots

See above

Additional context

If you were able to add an indent option so that we could turn on indentation folding as well as specific folding, that would also fix this and other issues.

Reference to the issue I've raised in VScode as well that relates to this issue: https://github.com/microsoft/vscode/issues/116652

daiyam commented 3 years ago

The following config should be working:

"folding": {
    "html": {
        "beginRegex": "<([a-zA-Z]+)",
        "endRegex": "<\\/\\1>",
    },
}
TotallyInformation commented 3 years ago

Hi, thanks for the quick reply.

No, that doesn't work either.

daiyam commented 3 years ago

Here what I get: Screenshot

What do you have?

TotallyInformation commented 3 years ago

image

Urm, odd - I got a single fold there. 2 others lower down as well. Seems random.

Not sure if it helps, but here is the full file:

https://github.com/TotallyInformation/node-red-contrib-uibuilder/blob/main/nodes/uibuilder.html

daiyam commented 3 years ago

It was due to <input which doesn't have a closing tag...

The following config is giving me:

"folding": {
    "html": {
        "beginRegex": "<(?!area|base|br|col|embed|hr|img|input|link|menuitem|meta|param|source|track|wbr)([a-zA-Z]+)[^>\\/]*>",
        "endRegex": "<\\/\\1>"
    },
}

Screenshot

(?!area|base|br|col|embed|hr|img|input|link|menuitem|meta|param|source|track|wbr) is excluding void html tags so they won't be matched as opening tags. [^>\\/]*> is excluding self-closed tags.

TotallyInformation commented 3 years ago

Fantastic - many thanks for that. Great job.