Skip to content

Commit 005ba46

Browse files
Haml: Improved filter and interpolation tokenization (#3191)
1 parent 4433d7f commit 005ba46

File tree

13 files changed

+198
-144
lines changed

13 files changed

+198
-144
lines changed

components/prism-haml.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@
9595
pattern: /^#\{|\}$/,
9696
alias: 'punctuation'
9797
},
98-
rest: Prism.languages.ruby
98+
'ruby': {
99+
pattern: /[\s\S]+/,
100+
inside: Prism.languages.ruby
101+
}
99102
}
100103
},
101104
'punctuation': {
@@ -131,7 +134,11 @@
131134
pattern: /^:[\w-]+/,
132135
alias: 'variable'
133136
},
134-
rest: Prism.languages[filter.language]
137+
'text': {
138+
pattern: /[\s\S]+/,
139+
alias: [filter.language, 'language-' + filter.language],
140+
inside: Prism.languages[filter.language]
141+
}
135142
}
136143
};
137144
}

components/prism-haml.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/coffeescript+haml/coffeescript_inclusion.test

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@
1010
[
1111
["filter-coffee", [
1212
["filter-name", ":coffee"],
13-
["string", "'This is coffee script'"]
13+
["text", [
14+
["string", "'This is coffee script'"]
15+
]]
1416
]],
1517
["punctuation", "~"],
1618
["filter-coffee", [
17-
["filter-name", ":coffee"],
18-
["string", "'This is coffee script'"]
19-
]]
19+
["filter-name", ":coffee"],
20+
["text", [
21+
["string", "'This is coffee script'"]
22+
]]
23+
]]
2024
]
2125

2226
----------------------------------------------------
2327

24-
Checks for CoffeeScript filter in Haml. The tilde serves only as a separator.
28+
Checks for CoffeeScript filter in Haml. The tilde serves only as a separator.

tests/languages/css+haml/css+haml_usage.test

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@
1010
[
1111
["filter-css", [
1212
["filter-name", ":css"],
13-
["selector", ".test"],
14-
["punctuation", "{"],
15-
["punctuation", "}"]
13+
["text", [
14+
["selector", ".test"],
15+
["punctuation", "{"],
16+
["punctuation", "}"]
17+
]]
1618
]],
1719
["punctuation", "~"],
1820
["filter-css", [
19-
["filter-name", ":css"],
20-
["selector", ".test"],
21-
["punctuation", "{"],
22-
["punctuation", "}"]
23-
]]
21+
["filter-name", ":css"],
22+
["text", [
23+
["selector", ".test"],
24+
["punctuation", "{"],
25+
["punctuation", "}"]
26+
]]
27+
]]
2428
]
2529

2630
----------------------------------------------------
2731

28-
Checks for CSS filter in Haml. The tilde serves only as a separator.
32+
Checks for CSS filter in Haml. The tilde serves only as a separator.

tests/languages/erb+haml/erb_inclusion.test

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@
1010
[
1111
["filter-erb", [
1212
["filter-name", ":erb"],
13-
["operator", "<"],
14-
["operator", "%"],
15-
["operator", "="],
16-
" render ",
17-
["variable", "@products"],
18-
["operator", "||"],
19-
["string", [
20-
"\"empty_list\""
21-
]],
22-
["operator", "%"],
23-
["operator", ">"]
13+
["text", [
14+
["operator", "<"],
15+
["operator", "%"],
16+
["operator", "="],
17+
" render ",
18+
["variable", "@products"],
19+
["operator", "||"],
20+
["string", ["\"empty_list\""]],
21+
["operator", "%"],
22+
["operator", ">"]
23+
]]
2424
]],
2525
["punctuation", "~"],
2626
["filter-erb", [
2727
["filter-name", ":erb"],
28-
["operator", "<"],
29-
["operator", "%"],
30-
["operator", "="],
31-
" render ",
32-
["variable", "@products"],
33-
["operator", "||"],
34-
["string", [
35-
"\"empty_list\""
36-
]],
37-
["delimiter", "%>"]
28+
["text", [
29+
["operator", "<"],
30+
["operator", "%"],
31+
["operator", "="],
32+
" render ",
33+
["variable", "@products"],
34+
["operator", "||"],
35+
["string", ["\"empty_list\""]],
36+
["delimiter", "%>"]
37+
]]
3838
]]
3939
]

tests/languages/haml/interpolation_feature.test

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
[
77
["interpolation", [
88
["delimiter", "#{"],
9-
["number", "42"],
9+
["ruby", [
10+
["number", "42"]
11+
]],
1012
["delimiter", "}"]
1113
]],
1214
["interpolation", [
1315
["delimiter", "#{"],
14-
["string", ["\"foobar\""]],
16+
["ruby", [
17+
["string", ["\"foobar\""]]
18+
]],
1519
["delimiter", "}"]
1620
]]
1721
]
1822

1923
----------------------------------------------------
2024

21-
Checks for interpolation in plain text.
25+
Checks for interpolation in plain text.

tests/languages/haml/tag_feature.test

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@
4242
["attributes", [
4343
["punctuation", "{"],
4444
["symbol", ":type"],
45-
["operator", "="], ["operator", ">"],
45+
["operator", "="],
46+
["operator", ">"],
4647
["string", ["\"text/javascript\""]],
4748
["punctuation", ","],
49+
4850
["symbol", ":src"],
49-
["operator", "="], ["operator", ">"],
51+
["operator", "="],
52+
["operator", ">"],
5053
["string", [
5154
"\"javascripts/script_",
5255
["interpolation", [
@@ -65,7 +68,8 @@
6568
["attributes", [
6669
["punctuation", "{"],
6770
["symbol", ":id"],
68-
["operator", "="], ["operator", ">"],
71+
["operator", "="],
72+
["operator", ">"],
6973
["punctuation", "["],
7074
["variable", "@item"],
7175
["punctuation", "."],
@@ -88,8 +92,8 @@
8892
["attr-value", "@title"],
8993
["attr-name", "href"],
9094
["punctuation", "="],
91-
["attr-value", "href"],
92-
["punctuation", ")"]
95+
["attr-value", "href"],
96+
["punctuation", ")"]
9397
]]
9498
]],
9599
["tag", [
@@ -138,7 +142,8 @@
138142
["attributes", [
139143
["punctuation", "{"],
140144
["symbol", ":id"],
141-
["operator", "="], ["operator", ">"],
145+
["operator", "="],
146+
["operator", ">"],
142147
["variable", "@article"],
143148
["punctuation", "."],
144149
"number",
@@ -150,8 +155,14 @@
150155
["tag", [".item"]],
151156

152157
["tag", ["%br/"]],
153-
["tag", ["%blockquote", ["punctuation", "<"]]],
154-
["tag", ["%img", ["punctuation", ">"]]]
158+
["tag", [
159+
"%blockquote",
160+
["punctuation", "<"]
161+
]],
162+
["tag", [
163+
"%img",
164+
["punctuation", ">"]
165+
]]
155166
]
156167

157168
----------------------------------------------------

tests/languages/javascript+haml/javascript_inclusion.test

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@
1010
[
1111
["filter-javascript", [
1212
["filter-name", ":javascript"],
13-
["number", "0xBadFace"]
13+
["text", [
14+
["number", "0xBadFace"]
15+
]]
1416
]],
1517
["punctuation", "~"],
1618
["filter-javascript", [
1719
["filter-name", ":javascript"],
18-
["number", "0xBadFace"]
20+
["text", [
21+
["number", "0xBadFace"]
22+
]]
1923
]]
2024
]
2125

2226
----------------------------------------------------
2327

24-
Checks for JavaScript filter in Haml. The tilde serves only as a separator.
28+
Checks for JavaScript filter in Haml. The tilde serves only as a separator.

tests/languages/less+haml/less_inclusion.test

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@
1010
[
1111
["filter-less", [
1212
["filter-name", ":less"],
13-
["selector", [".foo"]],
14-
["punctuation", "{"],
15-
["mixin-usage", ".bar"],
16-
["punctuation", ";"],
17-
["punctuation", "}"]
13+
["text", [
14+
["selector", [".foo"]],
15+
["punctuation", "{"],
16+
["mixin-usage", ".bar"],
17+
["punctuation", ";"],
18+
["punctuation", "}"]
19+
]]
1820
]],
1921
["punctuation", "~"],
2022
["filter-less", [
2123
["filter-name", ":less"],
22-
["selector", [".foo"]],
23-
["punctuation", "{"],
24-
["mixin-usage", ".bar"],
25-
["punctuation", ";"],
26-
["punctuation", "}"]
24+
["text", [
25+
["selector", [".foo"]],
26+
["punctuation", "{"],
27+
["mixin-usage", ".bar"],
28+
["punctuation", ";"],
29+
["punctuation", "}"]
30+
]]
2731
]]
2832
]
2933

3034
----------------------------------------------------
3135

32-
Checks for Less filter in Haml. The tilde serves only as a separator.
36+
Checks for Less filter in Haml. The tilde serves only as a separator.

tests/languages/markdown+haml/markdown_inclusion.test

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@
1010
[
1111
["filter-markdown", [
1212
["filter-name", ":markdown"],
13-
["title", [
14-
["punctuation", "#"],
15-
" Title 1"
13+
["text", [
14+
["title", [
15+
["punctuation", "#"],
16+
" Title 1"
17+
]]
1618
]]
1719
]],
1820
["punctuation", "~"],
1921
["filter-markdown", [
2022
["filter-name", ":markdown"],
21-
["title", [
22-
["punctuation", "#"],
23-
" Title 1"
24-
]]
23+
["text", [
24+
["title", [
25+
["punctuation", "#"],
26+
" Title 1"
27+
]]
28+
]]
2529
]]
2630
]
2731

2832
----------------------------------------------------
2933

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

0 commit comments

Comments
 (0)