I’m trying to enhance syntax highlighting for ruby files by adding the ability to recognize heredoc strings with embedded ERB. It already works for HTML, SQL, and a few other languages:
Digging into the Ruby syntax file, I found the sections related to heredoc language embedding and made a new one for erb:
heredocs:
# heredoc with embedded HTML and indented terminator
- match: '(<<[-~]"?((?:[_\w]+_|)HTML)\b"?)'
scope: punctuation.definition.string.begin.ruby
push: [heredoc-html, trailing-heredoc-start]
# heredoc with embedded ERB and indented terminator
- match: '(<<[-~]"?((?:[_\w]+_|)ERB)\b"?)'
scope: punctuation.definition.string.begin.ruby
push: [heredoc-erb, trailing-heredoc-start]
and
heredoc-html:
- meta_scope: string.unquoted.embedded.html.ruby
- meta_content_scope: text.html.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: scope:text.html.basic
- include: interpolated-ruby
- include: escaped-char
heredoc-erb:
- meta_scope: string.unquoted.embedded.html.ruby
- meta_content_scope: text.html.ruby.embedded.ruby
- match: ^\s*\2$
scope: punctuation.definition.string.end.ruby
pop: true
- include: scope:text.html.ruby
- include: interpolated-ruby
- include: escaped-char
Full syntax file here
With this modification, the ERB embedding works… sort of:
Any idea how I could get sublime to better recognize the end delimiter? I’m guessing it must be something about the language I’m embedding since HTML works fine.
As a side note, it’s interesting that the included CSS embedding has the same issue: