diff --git a/src/languages/ruby.js b/src/languages/ruby.js index e54ae8751b..d2f09d522d 100644 --- a/src/languages/ruby.js +++ b/src/languages/ruby.js @@ -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], + } + ] } ] }; diff --git a/test/markup/ruby/heredoc.expect.txt b/test/markup/ruby/heredoc.expect.txt index 18e27a5825..df3433066b 100644 --- a/test/markup/ruby/heredoc.expect.txt +++ b/test/markup/ruby/heredoc.expect.txt @@ -4,5 +4,12 @@ <h4>#{bar}</h4> </div> HTML +end def baz() + msg = <<~FOO + <div> + <h4>#{bar}</h4> + </div> + FOO +end diff --git a/test/markup/ruby/heredoc.txt b/test/markup/ruby/heredoc.txt index 15a8f08b31..ef7c6a1077 100644 --- a/test/markup/ruby/heredoc.txt +++ b/test/markup/ruby/heredoc.txt @@ -4,5 +4,12 @@ def foo()

#{bar}

HTML +end def baz() + msg = <<~FOO +
+

#{bar}

+
+ FOO +end \ No newline at end of file