From 5cdeb9a682e1cc22629e64d84a557a76764369b3 Mon Sep 17 00:00:00 2001 From: Rane Brown Date: Wed, 1 Jan 2020 10:58:56 -0700 Subject: [PATCH] Improve markdown syntax for fenced code blocks. Closes #764 --- autoload/vimwiki/base.vim | 2 +- doc/vimwiki.txt | 2 ++ syntax/vimwiki_markdown.vim | 4 ++-- test/syntax.vader | 29 ++++++++++++++++++++++++++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 0e812ef..ee5f7a8 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -2276,7 +2276,7 @@ endfunction function! vimwiki#base#detect_nested_syntax() abort let last_word = '\v.*<(\w+)\s*$' - let lines = map(filter(getline(1, '$'), 'v:val =~# "\\%({{{\\|```\\)" && v:val =~# last_word'), + let lines = map(filter(getline(1, '$'), 'v:val =~# "\\%({{{\\|`\\{3,\}\\|\\~\\{3,\}\\)" && v:val =~# last_word'), \ 'substitute(v:val, last_word, "\\=submatch(1)", "")') let dict = {} for elem in lines diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 292d6bd..796048e 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -3486,6 +3486,8 @@ https://github.com/vimwiki-backup/vimwiki/issues. 2.5 (in progress)~ New:~ + * Issue #764: fenced code blocks are properly supported for markdown + syntax i.e. more than 3 backticks, adds tilde support. * Set default |vimwiki-option-list_margin| = 0 for markdown syntax. * PR #785: |:VimwikiGoto| completion works with part of filename and nested directories diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim index e68661a..51896b0 100644 --- a/syntax/vimwiki_markdown.vim +++ b/syntax/vimwiki_markdown.vim @@ -80,8 +80,8 @@ let s:markdown_syntax.list_markers = ['-', '*', '+', '1.'] let s:markdown_syntax.rxListDefine = '::\%(\s\|$\)' " Preformatted text -let s:markdown_syntax.rxPreStart = '```' -let s:markdown_syntax.rxPreEnd = '```' +let s:markdown_syntax.rxPreStart = '\%(`\{3,}\|\~\{3,}\)' +let s:markdown_syntax.rxPreEnd = '\%(`\{3,}\|\~\{3,}\)' " Math block let s:markdown_syntax.rxMathStart = '\$\$' diff --git a/test/syntax.vader b/test/syntax.vader index ca22ce6..3cfe860 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -211,6 +211,21 @@ Given vimwiki (Markdown, Text and Vim): set hlsearch ``` + `````vim + " this is vim + set hlsearch + ````` + + ~~~vim + " this is vim + set hlsearch + ~~~ + + ~~~~~vim + " this is vim + set hlsearch + ~~~~~~~~~~~ + Execute (Set syntax markdown): let g:vimwiki_global_vars['vimwiki_automatic_nested_syntaxes'] = 1 call SetSyntax('markdown') @@ -225,6 +240,18 @@ Execute (Assert Code syntax): AssertEqual SyntaxAt(5, 1), 'VimwikiPre' AssertEqual SyntaxAt(9, 1), 'vimLineComment' AssertEqual SyntaxAt(10, 1), 'vimCommand' + AssertEqual SyntaxAt(13, 1), 'VimwikiPre' + AssertEqual SyntaxAt(14, 1), 'vimLineComment' + AssertEqual SyntaxAt(15, 1), 'vimCommand' + AssertEqual SyntaxAt(16, 1), 'VimwikiPre' + AssertEqual SyntaxAt(18, 1), 'VimwikiPre' + AssertEqual SyntaxAt(19, 1), 'vimLineComment' + AssertEqual SyntaxAt(20, 1), 'vimCommand' + AssertEqual SyntaxAt(21, 1), 'VimwikiPre' + AssertEqual SyntaxAt(23, 1), 'VimwikiPre' + AssertEqual SyntaxAt(24, 1), 'vimLineComment' + AssertEqual SyntaxAt(25, 1), 'vimCommand' + AssertEqual SyntaxAt(26, 1), 'VimwikiPre' # 11 Math {{{1 @@ -277,7 +304,7 @@ Given vimwiki (Math wiki): &= 2. }}$ -Execute (Set syntax markdown): +Execute (Set syntax default): call SetSyntax('default') Execute (Assert math syntax):