]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix syntax include errors with alias language
authorHiroshi Shirosaki <h.shirosaki@gmail.com>
Fri, 5 Feb 2016 02:17:25 +0000 (11:17 +0900)
committerHiroshi Shirosaki <h.shirosaki@gmail.com>
Fri, 5 Feb 2016 03:05:29 +0000 (12:05 +0900)
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

ftplugin/markdown.vim
test/syntax.vader

index d68e7c0a790aeeca9e1f55e574d05976bc363aaf..4019ff9f7dba69cb4ac77885d094cc2fec7ade78 100644 (file)
@@ -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)
index e5618f353ba38a5b13ea01b8fb893f9ab0b62b4a..8ac0a2823047634b20e4d1d0b437ab5adeb655ed 100644 (file)
@@ -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;
 ```
 =