Skip to content

Commit

Permalink
Merge pull request #583 from westonganger/gh-pages
Browse files Browse the repository at this point in the history
Added Ruby string interpolation
  • Loading branch information
Golmote committed Jul 11, 2015
2 parents 66dac31 + 5b1e07b commit c36b123
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 17 additions & 1 deletion components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* constant, builtin, variable, symbol, regex
*/
Prism.languages.ruby = Prism.languages.extend('clike', {
'comment': /#[^\r\n]*(\r?\n|$)/,
'comment': /#(?!\{[^\r\n]*?\})[^\r\n]*(\r?\n|$)/,
'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/,
'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/
Expand All @@ -19,3 +19,19 @@ Prism.languages.insertBefore('ruby', 'keyword', {
'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/,
'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/
});

Prism.languages.ruby.string = {
pattern: /("|')(#\{[^}]+\}|\\\n|\\?.)*?\1/,
inside: {
'interpolation': {
pattern: /#\{[^}]+\}/,
inside: {
'delimiter': {
pattern: /^#\{|\}$/,
alias: 'tag'
},
rest: Prism.util.clone(Prism.languages.ruby)
}
}
}
};
8 changes: 7 additions & 1 deletion examples/prism-ruby.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ <h2>Variables</h2>
<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 shows as ruby code</h3>
<pre><code>#{my_var}</code></pre>

<h3>Comment-like substrings</h3>
<pre><code>"foo # bar";</code></pre>

Expand All @@ -43,4 +49,4 @@ <h3>Multi-line comments are not supported</h3>
************************
This is a comment block
************************
=end</code></pre>
=end</code></pre>

0 comments on commit c36b123

Please sign in to comment.