tree-sitter-html icon indicating copy to clipboard operation
tree-sitter-html copied to clipboard

support self-closing style/script tags

Open milahu opened this issue 5 years ago • 3 comments

milahu avatar Nov 30 '20 10:11 milahu

error cos i did not include the new auto-generated parser files fixed in request #20

milahu avatar Nov 30 '20 10:11 milahu

From what I can tell, self-closing script and style tags are not allowed in HTML: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script

Tag omission None, both the starting and ending tag are mandatory

maxbrunsfeld avatar Nov 30 '20 20:11 maxbrunsfeld

aah, the html legacy .. self-closing script/style tags are parsed as open-tags https://stackoverflow.com/a/4531813/10440128

so this

<script/>
<script>true</script>

should be parsed as

(fragment
  (script_element
    (start_tag (tag_name))    ; <script/>
    (text)                    ; \n<script>true
    (end_tag (tag_name))      ; </script>
  )
)

actual result

(fragment
  (ERROR (tag_name))          ; <script/>
  (script_element
    (start_tag (tag_name))    ; <script>
    (raw_text)                ; true
    (end_tag (tag_name))      ; </script>
  )
)

failed attempt to fix

     script_start_tag: $ => seq(
       '<',
       alias($._script_start_tag_name, $.tag_name),
       repeat($.attribute),
+      optional('/'), // self-closing tag = open tag (legacy)
       '>'
     ),

i still get (ERROR (tag_name))

milahu avatar Dec 01 '20 09:12 milahu