Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ruby's squiggly heredoc #2049

Merged
merged 4 commits into from Aug 11, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/languages/ruby.js
Expand Up @@ -65,8 +65,16 @@ function(hljs) {
// is the last character of a preceding identifier, as in: `func?4`
begin: /\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/
},
{
begin: /<<(-?)\w+$/, end: /^\s*\w+$/,
{ // heredocs
begin: /<<[-~]?'?(\w+)(?:.|\n)*?\n\s*\1\b/,
returnBegin: true,
contains: [
{ begin: /<<[-~]?'?/ },
{ begin: /\w+/,
endSameAsBegin: true,
contains: [hljs.BACKSLASH_ESCAPE, SUBST],
}
]
}
]
};
Expand Down
7 changes: 7 additions & 0 deletions test/markup/ruby/heredoc.expect.txt
Expand Up @@ -4,5 +4,12 @@
&lt;h4&gt;<span class="hljs-subst">#{bar}</span>&lt;/h4&gt;
&lt;/div&gt;
HTML</span>
<span class="hljs-keyword">end</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">baz</span><span class="hljs-params">()</span></span>
msg = <span class="hljs-string">&lt;&lt;~FOO
&lt;div&gt;
&lt;h4&gt;<span class="hljs-subst">#{bar}</span>&lt;/h4&gt;
&lt;/div&gt;
FOO</span>
<span class="hljs-keyword">end</span>
7 changes: 7 additions & 0 deletions test/markup/ruby/heredoc.txt
Expand Up @@ -4,5 +4,12 @@ def foo()
<h4>#{bar}</h4>
</div>
HTML
end

def baz()
msg = <<~FOO
<div>
<h4>#{bar}</h4>
</div>
FOO
end