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
Syntax highlighting for GFM fenced backtick code blocks #15
Comments
So if I read this correctly, it's not that Liquid added any special support, but rather they are moving away from their own |
So what you're saying is that because vim-markdown already supports highlighting between fenced backticks, and because vim-liquid sets the liquid subtype to markdown, vim-liquid should thereby already be supporting highlighting between fenced backticks? For some reason, it doesn't work for me. Code between fenced backticks is colored with a single color, regardless of whether a language is given. I also ran |
You have to set |
I've got let g:markdown_fenced_languages=['bash=sh', 'css', 'haskell', 'html', 'latex=tex', 'python', 'ruby'] and also let g:liquid_highlight_types=g:markdown_fenced_languages for good measure. Syntax highlighting with fenced backticks works totally fine with What doesn't work is syntax highlighting with fenced backticks with What am I missing? |
Uh, not sure. I can confirm it's not working for me either, and I would consider that a bug. |
I've just encountered this as well. Is there a quick way to get around this like copying some portion of the g:markdown_fenced_languages stuff in $VIMRUNTIME/syntax/markdown.vim into .vim/after/ftplugin/liquid.vim or something? Grepping $VIMRUNTIME I found that $VIMRUNTIME/syntax/rmd.vim does their own fenced highlighting, based on the value of g:markdown_fenced_languages, but I can't figure out how to adopt their approach. Any ideas? |
Adopting the example in $VIMRUNTIME/syntax/rmd.vim I was able to hack together this, which I put at the end of the vim-liquid/syntax/liquid.vim file, and now the code blocks are being highlighted in liquid files. I'm sure you'll be able to do a much better job, but it's a start: if exists('g:markdown_fenced_languages')
if !exists('g:liquid_fenced_languages')
let g:liquid_fenced_languages = deepcopy(g:markdown_fenced_languages)
let g:markdown_fenced_languages = []
endif
else
let g:liquid_fenced_languages = []
endif
if !empty(g:liquid_fenced_languages)
for s:lang in g:liquid_fenced_languages
" When we have an alias we want to split it, e.g. 'bash=sh'
if s:lang =~# '='
let s:syntax_file = substitute(s:lang, '.*=', '', '') " => 'sh'
let s:codeblock_name = substitute(s:lang, '=.*', '', '') " => 'bash'
else
let s:syntax_file = s:lang
let s:codeblock_name = s:lang
endif
unlet! b:current_syntax
" examples:
" execute 'syntax include @Liquidbash syntax/sh.vim' when entry is 'bash=sh'
" execute 'syntax include @Liquidcpp syntax/cpp.vim' when entry is 'cpp'
execute 'syntax include @Liquid'.s:codeblock_name.' syntax/'.s:syntax_file.'.vim'
" Define region INSIDE backquotes as match
execute 'syntax region liquidFenced'.s:codeblock_name.' matchgroup=liquidCodeDelimiter start="^\s*```\s*'.s:codeblock_name.'\>.*$" matchgroup=liquidCodeDelimiter end="^\s*```\ze\s*$" keepend contains=@Liquid'.s:codeblock_name
unlet! s:lang
endfor
endif
hi def link liquidCodeDelimiter Delimiter |
liquid wasn't doing fenced highlighting like markdown does, so I hacked together an implementation by referencing how /usr/local/share/vim/vim82/syntax/rmd.vim did it, and put it in ~/.vim/after/syntax/liquid.vim and it works now. Need to test more before creating a PR for upsteam at https://github.com/tpope/vim-liquid. See the issue tpope/vim-liquid#15 for explanation and my solution.
Now that Jekyll (since v3.3.0) has embraced GFM fenced backticks for code blocks (see, e.g., here and here), would it be possible to add syntax highlighting for it in vim-liquid, just like what already exists in vim-markdown?
Alternatively, if this is too Jekyll-specific, how about adding syntax highlighting for YAML frontmatter in vim-markdown?
As it stands, if I edit a file with
ft=liquid
, I don't get fenced backtick highlighting, but if I setft=markdown
, I don't get YAML frontmatter highlighting.The text was updated successfully, but these errors were encountered: