Skip to content

Commit 3bbbaa3

Browse files
authored
Allow fenced code highlight in liquid (#609)
Resolves #608
1 parent aa7d685 commit 3bbbaa3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ftplugin/markdown.vim

+6-2
Original file line numberDiff line numberDiff line change
@@ -854,19 +854,23 @@ function! s:SyntaxInclude(filetype)
854854
return grouplistname
855855
endfunction
856856

857+
function! s:IsHighlightSourcesEnabledForBuffer()
858+
" Enable for markdown buffers, and for liquid buffers with markdown format
859+
return &filetype =~# 'markdown' || get(b:, 'liquid_subtype', '') =~# 'markdown'
860+
endfunction
857861

858862
function! s:MarkdownRefreshSyntax(force)
859863
" Use != to compare &syntax's value to use the same logic run on
860864
" $VIMRUNTIME/syntax/synload.vim.
861865
"
862866
" vint: next-line -ProhibitEqualTildeOperator
863-
if &filetype =~# 'markdown' && line('$') > 1 && &syntax != 'OFF'
867+
if s:IsHighlightSourcesEnabledForBuffer() && line('$') > 1 && &syntax != 'OFF'
864868
call s:MarkdownHighlightSources(a:force)
865869
endif
866870
endfunction
867871

868872
function! s:MarkdownClearSyntaxVariables()
869-
if &filetype =~# 'markdown'
873+
if s:IsHighlightSourcesEnabledForBuffer()
870874
unlet! b:mkd_included_filetypes
871875
endif
872876
endfunction

test/syntax.vader

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Before:
22
unlet! b:mkd_known_filetypes
33
unlet! b:mkd_included_filetypes
44
unlet! g:vim_markdown_math
5+
unlet! b:liquid_subtype
56

67
Given markdown;
78
a **b** c
@@ -855,6 +856,17 @@ a
855856
Execute (fenced code block with extended info strings):
856857
AssertEqual SyntaxOf('a'), 'mkdCode'
857858

859+
Given liquid;
860+
```vim
861+
let g:a = 1
862+
```
863+
864+
Execute (fenced code block syntax in liquid file with markdown subtype):
865+
let b:liquid_subtype = 'markdown'
866+
let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax')
867+
call b:func(0)
868+
AssertEqual SyntaxOf('g:a'), 'vimVar'
869+
858870
# Code Blocks in pre and code tag
859871

860872
Given markdown;

0 commit comments

Comments
 (0)