Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bindings/swift/TreeSitterHtml/html.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions bindings/swift/TreeSitterHtmlTests/TreeSitterHtmlTests.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 30 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = grammar({
name: 'html',

extras: $ => [
$.comment,
/\s+/,
],

Expand Down Expand Up @@ -48,6 +47,7 @@ module.exports = grammar({
$.script_element,
$.style_element,
$.erroneous_end_tag,
$.comment,
),

element: $ => choice(
Expand Down Expand Up @@ -122,20 +122,43 @@ module.exports = grammar({
)),
),

attribute_name: _ => /[^<>"'/=\s]+/,
attribute_name: _ => /[^<>"'/=\s&]+/,

attribute_value: _ => /[^<>"'=\s]+/,
attribute_value_fragment: _ => token.immediate(/[^<>"'=\s&]+/),
attribute_value: $ => repeat1(
choice(
$.attribute_value_fragment,
$.entity,
)
),

// An entity can be named, numeric (decimal), or numeric (hexacecimal). The
// longest entity name is 29 characters long, and the HTML spec says that
// no more will ever be added.
entity: _ => /&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?/,
entity: _ => token.immediate(/&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?/),

unescaped_single_attribute_value_fragment: _ => /[^'&]+/,
unescaped_double_attribute_value_fragment: _ => /[^"&]+/,

quoted_attribute_value: $ => choice(
seq('\'', optional(alias(/[^']+/, $.attribute_value)), '\''),
seq('"', optional(alias(/[^"]+/, $.attribute_value)), '"'),
seq(
'\'',
repeat(choice(
alias($.unescaped_single_attribute_value_fragment, $.attribute_value_fragment),
$.entity,
)),
'\''
),
seq(
'"',
repeat(choice(
alias($.unescaped_double_attribute_value_fragment, $.attribute_value_fragment),
$.entity,
)),
'"'
),
),

text: _ => /[^<>&\s]([^<>&]*[^<>&\s])?/,
text: _ => /[^<>&]+/,
},
});
3 changes: 2 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
(erroneous_end_tag_name) @tag.error
(doctype) @constant
(attribute_name) @attribute
(attribute_value) @string
(attribute_value_fragment) @string
(comment) @comment
(entity) @entity

[
"<"
Expand Down
112 changes: 75 additions & 37 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 34 additions & 3 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading