Skip to content

Commit

Permalink
Merge pull request #4 from calmyournerves/support-css-class-characters
Browse files Browse the repository at this point in the history
Add support for `:` and `/` in css class names
  • Loading branch information
kolen authored Jul 7, 2024
2 parents e2468e2 + c097bec commit 8527121
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ module.exports = grammar({
_element_rest_text: $ => token(prec(-3, /[^ \t][^\n]*/)),

// From css grammar https://github.com/tree-sitter/tree-sitter-css/blob/master/grammar.js
// Originally: /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/
css_identifier: $ => /(--|-?[a-zA-Z_])[a-zA-Z0-9-_]*/,
// Originally from Slim: /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/
// With added support for `:` and `/`
css_identifier: $ => /(--|-?[a-zA-Z_])[a-zA-Z0-9-_:\/]*/,

// From doc, mostly unclear, which means which
doctype: $ => seq(
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.json

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

7 changes: 4 additions & 3 deletions src/parser.c

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

19 changes: 19 additions & 0 deletions test/corpus/tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ span.menu.active
(attr_shortcut_class
(css_identifier)))))

================================
Tag and css classes with : and /
================================

span.hidden.lg:block.w-1/2

---

(source_file
(element
(tag_name)
(attr_shortcuts
(attr_shortcut_class
(css_identifier))
(attr_shortcut_class
(css_identifier))
(attr_shortcut_class
(css_identifier)))))

===============================
Tag with traling space modifier
===============================
Expand Down

0 comments on commit 8527121

Please sign in to comment.