Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@
inside: {
'interpolation': interpolation
}
},
{
pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
alias: 'heredoc-string',
greedy: true,
inside: {
'delimiter': {
pattern: /^<<[-~]?[a-z_]\w*|[a-z_]\w*$/i,
alias: 'symbol',
inside: {
'punctuation': /^<<[-~]?/
}
},
'interpolation': interpolation
}
},
{
pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
alias: 'heredoc-string',
greedy: true,
inside: {
'delimiter': {
pattern: /^<<[-~]?'[a-z_]\w*'|[a-z_]\w*$/i,
alias: 'symbol',
inside: {
'punctuation': /^<<[-~]?'|'$/,
}
}
}
}
];

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.

5 changes: 4 additions & 1 deletion examples/prism-ruby.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ <h2>Comments</h2>

<h2>Strings</h2>
<pre><code>"foo \"bar\" baz"
'foo \'bar\' baz'</code></pre>
'foo \'bar\' baz'
&lt;&lt;STRING
here's some #{string} contents
STRING</code></pre>

<h2>Regular expressions</h2>
<pre><code>/foo?[ ]*bar/</code></pre>
Expand Down
90 changes: 89 additions & 1 deletion tests/languages/ruby/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ bar"
%x[foo #{ 42 }]
%x<foo #{ 42 }>

<<STRING
foo #{42} bar
STRING
<<-STRING
foo #{42} bar
STRING
<<~STRING
foo #{42} bar
STRING
<<'STRING'
foo #{42} bar
STRING
<<-'STRING'
foo #{42} bar
STRING
<<~'STRING'
foo #{42} bar
STRING

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

[
Expand Down Expand Up @@ -279,9 +298,78 @@ bar"
["delimiter", "}"]
]],
">"
]],
["string", [
["delimiter", [
["punctuation", "<<"],
"STRING"
]],
"\r\n foo ",
["interpolation", [
["delimiter", "#{"],
["number", "42"],
["delimiter", "}"]
]],
" bar\r\n",
["delimiter", ["STRING"]]
]],
["string", [
["delimiter", [
["punctuation", "<<-"],
"STRING"
]],
"\r\n foo ",
["interpolation", [
["delimiter", "#{"],
["number", "42"],
["delimiter", "}"]
]],
" bar\r\n ",
["delimiter", ["STRING"]]
]],
["string", [
["delimiter", [
["punctuation", "<<~"],
"STRING"
]],
"\r\n foo ",
["interpolation", [
["delimiter", "#{"],
["number", "42"],
["delimiter", "}"]
]],
" bar\r\n ",
["delimiter", ["STRING"]]
]],
["string", [
["delimiter", [
["punctuation", "<<'"],
"STRING",
["punctuation", "'"]
]],
"\r\n foo #{42} bar\r\n",
["delimiter", ["STRING"]]
]],
["string", [
["delimiter", [
["punctuation", "<<-'"],
"STRING",
["punctuation", "'"]
]],
"\r\n foo #{42} bar\r\n ",
["delimiter", ["STRING"]]
]],
["string", [
["delimiter", [
["punctuation", "<<~'"],
"STRING",
["punctuation", "'"]
]],
"\r\n foo #{42} bar\r\n ",
["delimiter", ["STRING"]]
]]
]

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

Checks for strings and string interpolation.
Checks for strings and string interpolation.