Skip to content

Commit

Permalink
Ruby/ERB: Fixed block comments (#1768)
Browse files Browse the repository at this point in the history
This fixes block comments in Ruby and ERB.
  • Loading branch information
RunDevelopment authored Mar 5, 2019
1 parent 571704c commit c805f85
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/prism-erb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
});

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

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

}(Prism));
}(Prism));
2 changes: 1 addition & 1 deletion components/prism-erb.min.js

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

2 changes: 1 addition & 1 deletion components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'comment': [
/#.*/,
{
pattern: /^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m,
pattern: /^=begin\s[\s\S]*?^=end/m,
greedy: true
}
],
Expand Down
2 changes: 1 addition & 1 deletion components/prism-ruby.min.js

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

56 changes: 56 additions & 0 deletions tests/languages/erb/issue1767.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<%# this is a block comment %>
<%
=begin %>
block comment
(both lines of both the begin and end tags must be at the start of their lines)
<%
=end %>

<%# this is not %>
<%
=begin %>
not a comment
<%
=end %>

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

[
["erb", [
["delimiter", "<%"],
["comment", "# this is a block comment "],
["delimiter", "%>"]
]],

["erb", [
["delimiter", "<%"],
["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"],
["delimiter", "%>"]
]],

["erb", [
["delimiter", "<%"],
["comment", "# this is not "],
["delimiter", "%>"]
]],

["erb", [
["delimiter", "<%"],
["operator", "="],
["keyword", "begin"],
["delimiter", "%>"]
]],

"\n\tnot a comment\n\t",

["erb", [
["delimiter", "<%"],
["operator", "="],
["keyword", "end"],
["delimiter", "%>"]
]]
]

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

Checks for block comments (#1767).
5 changes: 4 additions & 1 deletion tests/languages/ruby/comment_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ foo bar baz
=end
=begin
=end
=begin foo
=end
#{comment}

----------------------------------------------------
Expand All @@ -14,9 +16,10 @@ foo bar baz
["comment", "# foobar"],
["comment", "=begin\r\nfoo bar baz\r\n=end"],
["comment", "=begin\r\n=end"],
["comment", "=begin foo\r\n=end"],
["comment", "#{comment}"]
]

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

Checks for comments.
Checks for comments.

0 comments on commit c805f85

Please sign in to comment.