Skip to content

Commit 909c0e5

Browse files
authored
Merge pull request preservim#492 from jrwrigh/master
feat: Allow characters after code fence language
2 parents 23a5146 + dfd92dd commit 909c0e5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ftplugin/markdown.vim

+3-2
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,8 @@ function! s:MarkdownHighlightSources(force)
788788
" Look for code blocks in the current file
789789
let filetypes = {}
790790
for line in getline(1, '$')
791-
let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*')
791+
let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*\ze.*')
792+
echom ft
792793
if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
793794
endfor
794795
if !exists('b:mkd_known_filetypes')
@@ -819,7 +820,7 @@ function! s:MarkdownHighlightSources(force)
819820
else
820821
let include = '@' . toupper(filetype)
821822
endif
822-
let command = 'syntax region %s matchgroup=%s start="^\s*```\s*%s$" matchgroup=%s end="\s*```$" keepend contains=%s%s'
823+
let command = 'syntax region %s matchgroup=%s start="^\s*```\s*%s.*$" matchgroup=%s end="\s*```$" keepend contains=%s%s'
823824
execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') && get(g:, 'vim_markdown_conceal', 1) && get(g:, 'vim_markdown_conceal_code_blocks', 1) ? ' concealends' : '')
824825
execute printf('syntax cluster mkdNonListItem add=%s', group)
825826

test/syntax.vader

+6
Original file line numberDiff line numberDiff line change
@@ -739,12 +739,18 @@ def a
739739
end
740740
```
741741

742+
```ruby {linenos=table,hl_lines=[8,"15-17"],linenostart=199}
743+
class b
744+
end
745+
```
746+
742747
Execute (fenced code block syntax with a language specifier):
743748
let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax')
744749
call b:func(0)
745750
AssertEqual SyntaxOf('include'), 'cInclude'
746751
AssertEqual SyntaxOf('code'), 'mkdSnippetCPP'
747752
AssertEqual SyntaxOf('def'), 'rubyDefine'
753+
AssertEqual SyntaxOf('class'), 'rubyClass'
748754

749755
Given markdown;
750756
``` c++

0 commit comments

Comments
 (0)