Skip to content

Commit

Permalink
Ruby: Add support for =begin =end comments. Manual merge of #1121.
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed May 8, 2017
1 parent 65cbaa9 commit 62cdaf8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*/
(function(Prism) {
Prism.languages.ruby = Prism.languages.extend('clike', {
'comment': /#(?!\{[^\r\n]*?\}).*/,
'comment': [
/#(?!\{[^\r\n]*?\}).*/,
/^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m
],
'keyword': /\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/
});

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.

10 changes: 7 additions & 3 deletions examples/prism-ruby.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<h1>Ruby</h1>
<p>To use this language, use the class "language-ruby".</p>

<h2>Single-line comments</h2>
<pre><code># This is a comment</code></pre>
<h2>Comments</h2>
<pre><code># This is a comment
=begin
Multi-line
comment
=end</code></pre>

<h2>Strings</h2>
<pre><code>"foo \"bar\" baz"
Expand Down Expand Up @@ -35,7 +39,7 @@ <h2>Known failures</h2>
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>

<h3>Comments that look like interpolation shows as ruby code</h3>
<h3>Comments that look like interpolation show as ruby code</h3>
<pre><code>#{my_var}</code></pre>

<h3>Multi-line comments are not supported</h3>
Expand Down
9 changes: 8 additions & 1 deletion tests/languages/ruby/comment_feature.test
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#
# foobar
=begin
foo bar baz
=end
=begin
=end

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

[
["comment", "#"],
["comment", "# foobar"]
["comment", "# foobar"],
["comment", "=begin\r\nfoo bar baz\r\n=end"],
["comment", "=begin\r\n=end"]
]

----------------------------------------------------
Expand Down

0 comments on commit 62cdaf8

Please sign in to comment.