From: Hiroshi Shirosaki Date: Fri, 5 Feb 2016 02:17:25 +0000 (+0900) Subject: Fix syntax include errors with alias language X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/7bfbcf41b6c2578fff0b14bf23c65d139bb81094?ds=inline;hp=2c44359fbba26ae9f39d574f8844f6002814e685 Fix syntax include errors with alias language When alias names of a language are used with fenced code block, syntax include is executed twice and causes errors. We add `b:mkd_included_filetypes` to check syntax included. Fix #251 --- diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index d68e7c0..4019ff9 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -631,6 +631,10 @@ function! s:MarkdownHighlightSources(force) if !exists('b:mkd_known_filetypes') let b:mkd_known_filetypes = {} endif + if !exists('b:mkd_included_filetypes') + " set syntax file name included + let b:mkd_included_filetypes = {} + endif if !a:force && (b:mkd_known_filetypes == filetypes || empty(filetypes)) return endif @@ -646,7 +650,12 @@ function! s:MarkdownHighlightSources(force) let filetype = ft endif let group = 'mkdSnippet' . toupper(substitute(filetype, "[+-]", "_", "g")) - let include = s:SyntaxInclude(filetype) + if !has_key(b:mkd_included_filetypes, filetype) + let include = s:SyntaxInclude(filetype) + let b:mkd_included_filetypes[filetype] = 1 + else + let include = '@' . toupper(filetype) + endif let command = 'syntax region %s matchgroup=%s start="^\s*```%s$" matchgroup=%s end="\s*```$" keepend contains=%s%s' execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') ? ' concealends' : '') execute printf('syntax cluster mkdNonListItem add=%s', group) diff --git a/test/syntax.vader b/test/syntax.vader index e5618f3..8ac0a28 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -375,6 +375,21 @@ Execute (fenced code block syntax with a language specifier): AssertEqual SyntaxOf('code'), 'mkdSnippetCPP' AssertEqual SyntaxOf('def'), 'rubyDefine' +Given markdown; +```vim +let g:a = 1 +``` + +```viml +let g:b = 1 +``` + +Execute (fenced code block syntax with alias language specifier): + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax') + call b:func(0) + AssertEqual SyntaxOf('g:a'), 'vimVar' + AssertEqual SyntaxOf('g:b'), 'vimVar' + Given markdown; ```a+b- code @@ -385,7 +400,6 @@ Execute (fenced code block syntax with an unknown language specifier): call b:func(0) AssertEqual SyntaxOf('code'), 'mkdSnippetA_B_' - Given markdown; ``` =