Skip to content

Commit

Permalink
Ruby: Make multi-line comments greedy, remove single-line comment hac…
Browse files Browse the repository at this point in the history
…k. Update known failures and tests.
  • Loading branch information
Golmote committed Mar 26, 2018
1 parent a0f5081 commit b0e34fb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
7 changes: 5 additions & 2 deletions components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
(function(Prism) {
Prism.languages.ruby = Prism.languages.extend('clike', {
'comment': [
/#(?!\{[^\r\n]*?\}).*/,
/^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m
/#.*/,
{
pattern: /^=begin(?:\r?\n|\r)(?:.*(?:\r?\n|\r))*?=end/m,
greedy: true
}
],
'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|protected|private|public|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.

12 changes: 1 addition & 11 deletions examples/prism-ruby.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,4 @@ <h2>Symbols</h2>
<pre><code>mystring = :steveT;</code></pre>

<h2>String Interpolation</h2>
<pre><code>"foo #{'bar'+my_variable}"</code></pre>

<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
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 show as ruby code</h3>
<pre><code>#{my_var}</code></pre>
<pre><code>"foo #{'bar'+my_variable}"</code></pre>
4 changes: 3 additions & 1 deletion tests/languages/ruby/comment_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ foo bar baz
=end
=begin
=end
#{comment}

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

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

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

0 comments on commit b0e34fb

Please sign in to comment.