8000 Ruby/ERB: Fixed block comments (#1768) · PrismJS/prism@c805f85 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c805f85

Browse files
Ruby/ERB: Fixed block comments (#1768)
This fixes block comments in Ruby and ERB.
1 parent 571704c commit c805f85

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

components/prism-erb.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
});
1010

1111
Prism.hooks.add('before-tokenize', function(env) {
12-
var erbPattern = /<%=?[\s\S]+?%>/g;
12+
var erbPattern = /<%=?(?:[^\r\n]|[\r\n](?!=begin)|[\r\n]=begin\s[\s\S]*?^=end)+?%>/gm;
1313
Prism.languages['markup-templating'].buildPlaceholders(env, 'erb', erbPattern);
1414
});
1515

1616
Prism.hooks.add('after-tokenize', function(env) {
1717
Prism.languages['markup-templating'].tokenizePlaceholders(env, 'erb');
1818
});
1919

20-
}(Prism));
20+
}(Prism));

components/prism-erb.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-ruby.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'comment': [
1010
/#.*/,
1111
{
12-
pattern: /^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m,
12+
pattern: /^=begin\s[\s\S]*?^=end/m,
1313
greedy: true
1414
}
1515
],

components/prism-ruby.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/erb/issue1767.test

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<%# this is a block comment %>
2+
<%
3+
=begin %>
4+
block comment
5+
(both lines of both the begin and end tags must be at the start of their lines)
6+
<%
7+
=end %>
8+
9+
<%# this is not %>
10+
<%
11+
=begin %>
12+
not a comment
13+
<%
14+
=end %>
15+
16+
----------------------------------------------------
17+
18+
[
19+
["erb", [
20+
["delimiter", "<%"],
21+
["comment", "# this is a block comment "],
22+
["delimiter", "%>"]
23+
]],
24+
25+
["erb", [
26+
["delimiter", "<%"],
27+
["comment", "=begin %>\n\tblock comment\n\t(both lines of both the begin and end tags must be at the start of their lines)\n<%\n=end"],
28+
["delimiter", "%>"]
29+
]],
30+
31+
["erb", [
32+
["delimiter", "<%"],
33+
["comment", "# this is not "],
34+
["delimiter", "%>"]
35+
]],
36+
37+
["erb", [
38+
["delimiter", "<%"],
39+
["operator", "="],
40+
["keyword", "begin"],
41+
["delimiter", "%>"]
42+
]],
43+
44+
"\n\tnot a comment\n\t",
45+
46+
["erb", [
47+
["delimiter", "<%"],
48+
["operator", "="],
49+
["keyword", "end"],
50+
["delimiter", "%>"]
51+
]]
52+
]
53+
54+
----------------------------------------------------
55+
56+
Checks for block comments (#1767).

tests/languages/ruby/comment_feature.test

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ foo bar baz
55
=end
66
=begin
77
=end
8+
=begin foo
9+
=end
810
#{comment}
911

1012
----------------------------------------------------
@@ -14,9 +16,10 @@ foo bar baz
1416
["comment", "# foobar"],
1517
["comment", "=begin\r\nfoo bar baz\r\n=end"],
1618
["comment", "=begin\r\n=end"],
19+
["comment", "=begin foo\r\n=end"],
1720
["comment", "#{comment}"]
1821
]
1922

2023
----------------------------------------------------
2124

22-
Checks for comments.
25+
Checks for comments.

0 commit comments

Comments
 (0)
0