Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Haml: Improved filter and interpolation tokenization (#3191)
  • Loading branch information
RunDevelopment committed Nov 10, 2021
1 parent 4433d7f commit 005ba46
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 144 deletions.
11 changes: 9 additions & 2 deletions components/prism-haml.js
Expand Up @@ -95,7 +95,10 @@
pattern: /^#\{|\}$/,
alias: 'punctuation'
},
rest: Prism.languages.ruby
'ruby': {
pattern: /[\s\S]+/,
inside: Prism.languages.ruby
}
}
},
'punctuation': {
Expand Down Expand Up @@ -131,7 +134,11 @@
pattern: /^:[\w-]+/,
alias: 'variable'
},
rest: Prism.languages[filter.language]
'text': {
pattern: /[\s\S]+/,
alias: [filter.language, 'language-' + filter.language],
inside: Prism.languages[filter.language]
}
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-haml.min.js

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

14 changes: 9 additions & 5 deletions tests/languages/coffeescript+haml/coffeescript_inclusion.test
Expand Up @@ -10,15 +10,19 @@
[
["filter-coffee", [
["filter-name", ":coffee"],
["string", "'This is coffee script'"]
["text", [
["string", "'This is coffee script'"]
]]
]],
["punctuation", "~"],
["filter-coffee", [
["filter-name", ":coffee"],
["string", "'This is coffee script'"]
]]
["filter-name", ":coffee"],
["text", [
["string", "'This is coffee script'"]
]]
]]
]

----------------------------------------------------

Checks for CoffeeScript filter in Haml. The tilde serves only as a separator.
Checks for CoffeeScript filter in Haml. The tilde serves only as a separator.
22 changes: 13 additions & 9 deletions tests/languages/css+haml/css+haml_usage.test
Expand Up @@ -10,19 +10,23 @@
[
["filter-css", [
["filter-name", ":css"],
["selector", ".test"],
["punctuation", "{"],
["punctuation", "}"]
["text", [
["selector", ".test"],
["punctuation", "{"],
["punctuation", "}"]
]]
]],
["punctuation", "~"],
["filter-css", [
["filter-name", ":css"],
["selector", ".test"],
["punctuation", "{"],
["punctuation", "}"]
]]
["filter-name", ":css"],
["text", [
["selector", ".test"],
["punctuation", "{"],
["punctuation", "}"]
]]
]]
]

----------------------------------------------------

Checks for CSS filter in Haml. The tilde serves only as a separator.
Checks for CSS filter in Haml. The tilde serves only as a separator.
42 changes: 21 additions & 21 deletions tests/languages/erb+haml/erb_inclusion.test
Expand Up @@ -10,30 +10,30 @@
[
["filter-erb", [
["filter-name", ":erb"],
["operator", "<"],
["operator", "%"],
["operator", "="],
" render ",
["variable", "@products"],
["operator", "||"],
["string", [
"\"empty_list\""
]],
["operator", "%"],
["operator", ">"]
["text", [
["operator", "<"],
["operator", "%"],
["operator", "="],
" render ",
["variable", "@products"],
["operator", "||"],
["string", ["\"empty_list\""]],
["operator", "%"],
["operator", ">"]
]]
]],
["punctuation", "~"],
["filter-erb", [
["filter-name", ":erb"],
["operator", "<"],
["operator", "%"],
["operator", "="],
" render ",
["variable", "@products"],
["operator", "||"],
["string", [
"\"empty_list\""
]],
["delimiter", "%>"]
["text", [
["operator", "<"],
["operator", "%"],
["operator", "="],
" render ",
["variable", "@products"],
["operator", "||"],
["string", ["\"empty_list\""]],
["delimiter", "%>"]
]]
]]
]
10 changes: 7 additions & 3 deletions tests/languages/haml/interpolation_feature.test
Expand Up @@ -6,16 +6,20 @@
[
["interpolation", [
["delimiter", "#{"],
["number", "42"],
["ruby", [
["number", "42"]
]],
["delimiter", "}"]
]],
["interpolation", [
["delimiter", "#{"],
["string", ["\"foobar\""]],
["ruby", [
["string", ["\"foobar\""]]
]],
["delimiter", "}"]
]]
]

----------------------------------------------------

Checks for interpolation in plain text.
Checks for interpolation in plain text.
27 changes: 19 additions & 8 deletions tests/languages/haml/tag_feature.test
Expand Up @@ -42,11 +42,14 @@
["attributes", [
["punctuation", "{"],
["symbol", ":type"],
["operator", "="], ["operator", ">"],
["operator", "="],
["operator", ">"],
["string", ["\"text/javascript\""]],
["punctuation", ","],

["symbol", ":src"],
["operator", "="], ["operator", ">"],
["operator", "="],
["operator", ">"],
["string", [
"\"javascripts/script_",
["interpolation", [
Expand All @@ -65,7 +68,8 @@
["attributes", [
["punctuation", "{"],
["symbol", ":id"],
["operator", "="], ["operator", ">"],
["operator", "="],
["operator", ">"],
["punctuation", "["],
["variable", "@item"],
["punctuation", "."],
Expand All @@ -88,8 +92,8 @@
["attr-value", "@title"],
["attr-name", "href"],
["punctuation", "="],
["attr-value", "href"],
["punctuation", ")"]
["attr-value", "href"],
["punctuation", ")"]
]]
]],
["tag", [
Expand Down Expand Up @@ -138,7 +142,8 @@
["attributes", [
["punctuation", "{"],
["symbol", ":id"],
["operator", "="], ["operator", ">"],
["operator", "="],
["operator", ">"],
["variable", "@article"],
["punctuation", "."],
"number",
Expand All @@ -150,8 +155,14 @@
["tag", [".item"]],

["tag", ["%br/"]],
["tag", ["%blockquote", ["punctuation", "<"]]],
["tag", ["%img", ["punctuation", ">"]]]
["tag", [
"%blockquote",
["punctuation", "<"]
]],
["tag", [
"%img",
["punctuation", ">"]
]]
]

----------------------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions tests/languages/javascript+haml/javascript_inclusion.test
Expand Up @@ -10,15 +10,19 @@
[
["filter-javascript", [
["filter-name", ":javascript"],
["number", "0xBadFace"]
["text", [
["number", "0xBadFace"]
]]
]],
["punctuation", "~"],
["filter-javascript", [
["filter-name", ":javascript"],
["number", "0xBadFace"]
["text", [
["number", "0xBadFace"]
]]
]]
]

----------------------------------------------------

Checks for JavaScript filter in Haml. The tilde serves only as a separator.
Checks for JavaScript filter in Haml. The tilde serves only as a separator.
26 changes: 15 additions & 11 deletions tests/languages/less+haml/less_inclusion.test
Expand Up @@ -10,23 +10,27 @@
[
["filter-less", [
["filter-name", ":less"],
["selector", [".foo"]],
["punctuation", "{"],
["mixin-usage", ".bar"],
["punctuation", ";"],
["punctuation", "}"]
["text", [
["selector", [".foo"]],
["punctuation", "{"],
["mixin-usage", ".bar"],
["punctuation", ";"],
["punctuation", "}"]
]]
]],
["punctuation", "~"],
["filter-less", [
["filter-name", ":less"],
["selector", [".foo"]],
["punctuation", "{"],
["mixin-usage", ".bar"],
["punctuation", ";"],
["punctuation", "}"]
["text", [
["selector", [".foo"]],
["punctuation", "{"],
["mixin-usage", ".bar"],
["punctuation", ";"],
["punctuation", "}"]
]]
]]
]

----------------------------------------------------

Checks for Less filter in Haml. The tilde serves only as a separator.
Checks for Less filter in Haml. The tilde serves only as a separator.
20 changes: 12 additions & 8 deletions tests/languages/markdown+haml/markdown_inclusion.test
Expand Up @@ -10,23 +10,27 @@
[
["filter-markdown", [
["filter-name", ":markdown"],
["title", [
["punctuation", "#"],
" Title 1"
["text", [
["title", [
["punctuation", "#"],
" Title 1"
]]
]]
]],
["punctuation", "~"],
["filter-markdown", [
["filter-name", ":markdown"],
["title", [
["punctuation", "#"],
" Title 1"
]]
["text", [
["title", [
["punctuation", "#"],
" Title 1"
]]
]]
]]
]

----------------------------------------------------

Checks for Markdown filter in Haml. The tilde serves only as a separator.
Indentation is intentionally less than 1 tab, otherwise markdown is
interpreted as code.
interpreted as code.

0 comments on commit 005ba46

Please sign in to comment.