From dc9e985df1102c9204690a15596eaef07d9cfbb3 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Tue, 19 Jan 2016 10:36:56 +0900 Subject: [PATCH 01/16] Improve syntax regexp performance Use \zs instead of \@<= if possible. --- syntax/markdown.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 63429b3..f14c867 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -35,12 +35,12 @@ syn case ignore syn sync linebreaks=1 "additions to HTML groups -syn region htmlItalic start="\\\@ Date: Tue, 19 Jan 2016 11:19:34 +0900 Subject: [PATCH 02/16] Simplify the regexp of italic and bold Simplify the regexp to improve syntax performance. Use \ze instead of \@=. --- syntax/markdown.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index f14c867..c21d639 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -35,12 +35,12 @@ syn case ignore syn sync linebreaks=1 "additions to HTML groups -syn region htmlItalic start="\\\@ Date: Tue, 19 Jan 2016 11:26:25 +0900 Subject: [PATCH 03/16] Remove ' in regexp pattern of url --- syntax/markdown.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index c21d639..39d5e53 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -57,7 +57,7 @@ syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A syntax region mkdInlineURL matchgroup=mkdDelimiter start="(\(https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*)\)\@=" end=")" " Autolink with angle brackets. -syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@ ]*>\)\@=" end=">" +syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@ ]*>\)\@=" end=">" " Link definitions: [id]: URL (Optional Title) syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite -- 2.39.5 From 31f209886ce824a5a998e932359f77f9aac5d289 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Tue, 19 Jan 2016 11:43:22 +0900 Subject: [PATCH 04/16] Drop defined known scheme Shorten the regexp because the long pattern is very slow. --- syntax/markdown.vim | 2 +- test/syntax.vader | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 39d5e53..ec12ef6 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -57,7 +57,7 @@ syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A syntax region mkdInlineURL matchgroup=mkdDelimiter start="(\(https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*)\)\@=" end=")" " Autolink with angle brackets. -syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@ ]*>\)\@=" end=">" +syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@ ]*>" end=">" " Link definitions: [id]: URL (Optional Title) syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite diff --git a/test/syntax.vader b/test/syntax.vader index 7d6f6b1..d985b2c 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -107,12 +107,6 @@ Given markdown; Execute (autolink with scheme case is insensitive): AssertEqual SyntaxOf('a'), 'mkdInlineURL' -Given markdown; - - -Execute (autolink without known scheme is not a link): - AssertNotEqual SyntaxOf('n'), 'mkdInlineURL' - Given markdown; -- 2.39.5 From 2cbdce375bb945fecb3f110437b595dcc6dad566 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Tue, 19 Jan 2016 13:40:05 +0900 Subject: [PATCH 05/16] Improve regexp performance of italic Add tests for escaped asterisks. --- syntax/markdown.vim | 4 ++-- test/syntax.vader | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index ec12ef6..452a717 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -35,8 +35,8 @@ syn case ignore syn sync linebreaks=1 "additions to HTML groups -syn region htmlItalic start="\\\@ Date: Tue, 19 Jan 2016 14:19:39 +0900 Subject: [PATCH 06/16] Fix regexp for spaces \s is not spaces in []. --- syntax/markdown.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 452a717..b812698 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -35,8 +35,8 @@ syn case ignore syn sync linebreaks=1 "additions to HTML groups -syn region htmlItalic start="\\\@ Date: Tue, 19 Jan 2016 18:14:47 +0900 Subject: [PATCH 07/16] Restore number setting on tests --- test/toc-autofit.vader | 1 + 1 file changed, 1 insertion(+) diff --git a/test/toc-autofit.vader b/test/toc-autofit.vader index d35f50a..2678997 100644 --- a/test/toc-autofit.vader +++ b/test/toc-autofit.vader @@ -47,6 +47,7 @@ Execute (toc window autofit width): :lclose let expected_width = len(line) + 2*5 + 1 + 3 - 7 AssertEqual real_width, expected_width + set nonumber " 2 spaces * 5 additional header levels + 1 space for first header + " 3 spaces for line numbers - 7 chars ('###### ') that don't show up on the TOC -- 2.39.5 From d8309be06a202b1bd6a9a2dd8eacc6e9b10e459b Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Tue, 19 Jan 2016 18:18:04 +0900 Subject: [PATCH 08/16] Concealing links Add conceal to syntax link to help readability. Fix #244 --- README.md | 12 ++++++++++++ syntax/markdown.vim | 13 ++++++++++--- test/syntax.vader | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6020381..ec200b6 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,18 @@ It never increases its default size (half screen), it only shrinks. let g:vim_markdown_toc_autofit = 1 ``` +### Syntax Concealing + +Concealing is set for some syntax. + +For example, conceal `[link text](link url)` as just `link text`. + +To enable/disable conceal use Vim's standard conceal configuration. + +```vim +set conceallevel = 2 +``` + ### Syntax extensions The following options control which syntax extensions will be turned on. They are off by default. diff --git a/syntax/markdown.vim b/syntax/markdown.vim index b812698..46eb5a9 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -34,6 +34,13 @@ syn spell toplevel syn case ignore syn sync linebreaks=1 +let s:conceal = '' +let s:concealends = '' +if has('conceal') + let s:conceal = ' conceal' + let s:concealends = ' concealends' +endif + "additions to HTML groups syn region htmlItalic start="\\\@ Date: Tue, 19 Jan 2016 18:21:32 +0900 Subject: [PATCH 09/16] Update doc --- doc/vim-markdown.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/vim-markdown.txt b/doc/vim-markdown.txt index 74b9748..12ce7c8 100644 --- a/doc/vim-markdown.txt +++ b/doc/vim-markdown.txt @@ -11,7 +11,8 @@ Contents ~ 3. Set header folding level |vim-markdown-set-header-folding-level| 4. Disable Default Key Mappings |vim-markdown-disable-default-key-mappings| 5. Enable TOC window auto-fit |vim-markdown-enable-toc-window-auto-fit| - 6. Syntax extensions |vim-markdown-syntax-extensions| + 6. Syntax Concealing |vim-markdown-syntax-concealing| + 7. Syntax extensions |vim-markdown-syntax-extensions| 1. LaTeX math |vim-markdown-latex-math| 2. YAML frontmatter |vim-markdown-yaml-frontmatter| 4. Mappings |vim-markdown-mappings| @@ -119,6 +120,18 @@ never increases its default size (half screen), it only shrinks. > let g:vim_markdown_toc_autofit = 1 < +------------------------------------------------------------------------------- + *vim-markdown-syntax-concealing* +Syntax Concealing ~ + +Concealing is set for some syntax. + +For example, conceal '[link text](link url)' as just 'link text'. + +To enable/disable conceal use Vim's standard conceal configuration. +> + set conceallevel = 2 +< ------------------------------------------------------------------------------- *vim-markdown-syntax-extensions* Syntax extensions ~ -- 2.39.5 From fd74fcdff5cf237083beb93a7f7f1c5657c8dfa5 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Tue, 19 Jan 2016 21:02:23 +0900 Subject: [PATCH 10/16] Change function name to camel case as others --- ftplugin/markdown.vim | 18 +++++++++--------- test/syntax.vader | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index c43b0bd..1ce35a8 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -609,7 +609,7 @@ let s:filetype_dict = { \ 'viml': 'vim' \ } -function! s:Markdown_highlight_sources(force) +function! s:MarkdownHighlightSources(force) " Syntax highlight source code embedded in notes. " Look for code blocks in the current file let filetypes = {} @@ -635,7 +635,7 @@ function! s:Markdown_highlight_sources(force) let filetype = ft endif let group = 'mkdSnippet' . toupper(substitute(filetype, "[+-]", "_", "g")) - let include = s:syntax_include(filetype) + let include = s:SyntaxInclude(filetype) 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) @@ -645,7 +645,7 @@ function! s:Markdown_highlight_sources(force) endfor endfunction -function! s:syntax_include(filetype) +function! s:SyntaxInclude(filetype) " Include the syntax highlighting of another {filetype}. let grouplistname = '@' . toupper(a:filetype) " Unset the name of the current syntax while including the other syntax @@ -670,16 +670,16 @@ function! s:syntax_include(filetype) endfunction -function! s:Markdown_refresh_syntax(force) +function! s:MarkdownRefreshSyntax(force) if &filetype == 'markdown' && line('$') > 1 - call s:Markdown_highlight_sources(a:force) + call s:MarkdownHighlightSources(a:force) endif endfunction augroup Mkd autocmd! - au BufWinEnter * call s:Markdown_refresh_syntax(1) - au BufWritePost * call s:Markdown_refresh_syntax(0) - au InsertEnter,InsertLeave * call s:Markdown_refresh_syntax(0) - au CursorHold,CursorHoldI * call s:Markdown_refresh_syntax(0) + au BufWinEnter * call s:MarkdownRefreshSyntax(1) + au BufWritePost * call s:MarkdownRefreshSyntax(0) + au InsertEnter,InsertLeave * call s:MarkdownRefreshSyntax(0) + au CursorHold,CursorHoldI * call s:MarkdownRefreshSyntax(0) augroup END diff --git a/test/syntax.vader b/test/syntax.vader index bdc599f..e63ce7e 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -268,7 +268,7 @@ end ``` Execute (fenced code block syntax with a language specifier): - let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_refresh_syntax') + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax') call b:func(0) AssertEqual SyntaxOf('include'), 'cInclude' AssertEqual SyntaxOf('code'), 'mkdSnippetCPP' @@ -280,7 +280,7 @@ code ``` Execute (fenced code block syntax with an unknown language specifier): - let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'Markdown_refresh_syntax') + let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax') call b:func(0) AssertEqual SyntaxOf('code'), 'mkdSnippetA_B_' -- 2.39.5 From da8a4756efb2b2d9140f610c95dcf3adc1bdb9ba Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Tue, 19 Jan 2016 07:20:47 -0500 Subject: [PATCH 11/16] Make contributing headers h2 like README --- CONTRIBUTING.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 832072d..86912a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,18 +1,20 @@ +# CONTRIBUTING + These contributing guidelines were accepted rather late in the history of this plugin, after much code had already been written. If you find any existing behavior which does not conform to these guidelines, please correct it and send a pull request. -# General Rules +## General Rules Every non local identifier must start with `g:vim_markdown_`. -# Documentation +## Documentation Every new feature must be documented under in the [README.md](README.md). Documentation must be written in [GFM](https://help.github.com/articles/github-flavored-markdown) since GitHub itself is the primary to HTML converter used. In particular, remember that GFM adds line breaks at single newlines, so just forget about the 70 characters wide rule. Vim help file [doc/vim-markdown.txt](doc/vim-markdown.txt) will be generated from [README.md](README.md) by `make doc` using [vim-tools](https://github.com/xolox/vim-tools). -# Markdown Flavors +## Markdown Flavors There are many flavors of markdown, each one with an unique feature set. This plugin uses the following strategy to deal with all those flavors: @@ -30,17 +32,17 @@ There are many flavors of markdown, each one with an unique feature set. This pl Next, if there are many more than one Jekyll feature options, create a `g:vim_markdown_jekyll` option that turns them all on at once. -# Style +## Style When choosing between multiple valid Markdown syntaxes, the default behavior must be that specified at: If you wish to have a behavior that differs from that style guide, add an option to turn it on or off, and leave it off by default. -# Tests +## Tests All new features must have unit tests. -# Issues +## Issues Issues are tracked within GitHub. -- 2.39.5 From 1b37c6c879c6fcdd5f96ef12b95eeda2e0b416e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?utf8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F=20=E5=8C=85=E5=8D=93=E8=BD=A9?= Date: Tue, 19 Jan 2016 07:38:26 -0500 Subject: [PATCH 12/16] Remove extra blank line from README markdown --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index ec200b6..0328b7f 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,6 @@ Highlight YAML frontmatter as used by Jekyll: let g:vim_markdown_frontmatter = 1 ``` - ## Mappings The following work on normal and visual modes: -- 2.39.5 From 07f5c794b9885bf53dd5c9c9c6b72a5bb135ec67 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Tue, 19 Jan 2016 22:29:22 +0900 Subject: [PATCH 13/16] Not allow space in link No spaces between link text and the following parenthesis. http://spec.commonmark.org/0.24/#example-474 --- syntax/markdown.vim | 2 +- test/syntax.vader | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 46eb5a9..92c6c56 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -53,7 +53,7 @@ syn region htmlBoldItalic start="___\ze\S" end="\S\zs___" keepend oneline syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]" execute 'syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline' . s:conceal execute 'syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline' . s:conceal -execute 'syn region mkdLink matchgroup=mkdDelimiter start="\\\@ Date: Wed, 20 Jan 2016 09:06:49 +0900 Subject: [PATCH 14/16] Remove spaces around = of set option Spaces are not allowed. --- README.md | 2 +- doc/vim-markdown.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0328b7f..1243577 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ For example, conceal `[link text](link url)` as just `link text`. To enable/disable conceal use Vim's standard conceal configuration. ```vim -set conceallevel = 2 +set conceallevel=2 ``` ### Syntax extensions diff --git a/doc/vim-markdown.txt b/doc/vim-markdown.txt index 12ce7c8..1dd0465 100644 --- a/doc/vim-markdown.txt +++ b/doc/vim-markdown.txt @@ -130,7 +130,7 @@ For example, conceal '[link text](link url)' as just 'link text'. To enable/disable conceal use Vim's standard conceal configuration. > - set conceallevel = 2 + set conceallevel=2 < ------------------------------------------------------------------------------- *vim-markdown-syntax-extensions* -- 2.39.5 From 1509003ccdff6bf1f7777ceefc09f9cb32abf986 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Wed, 20 Jan 2016 14:53:09 +0900 Subject: [PATCH 15/16] Fix indent code block at beginning of file Fix #105 --- syntax/markdown.vim | 1 + test/syntax.vader | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 92c6c56..79e1a3c 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -96,6 +96,7 @@ syn region mkdCode start="]*>" end="" syn region mkdCode start="]*>" end="" syn region mkdFootnote start="\[^" end="\]" syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/ +syn match mkdCode /\%^\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained syn region mkdListItemLine matchgroup=mkdListItem start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" contains=@mkdNonListItem,@Spell syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell diff --git a/test/syntax.vader b/test/syntax.vader index c438dad..b5d1937 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -263,6 +263,14 @@ Execute (indent code blocks after list): AssertNotEqual SyntaxOf('b'), 'mkdCode' AssertEqual SyntaxOf('c'), 'mkdCode' +Given markdown; + a + b + +Execute (indent code block at beginning of file): + AssertEqual SyntaxOf('a'), 'mkdCode' + AssertEqual SyntaxOf('b'), 'mkdCode' + Given markdown; ```c++ #include -- 2.39.5 From 1d04101ca7e3de1b622f356e33cfbaeb5e358bc9 Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Wed, 20 Jan 2016 15:01:09 +0900 Subject: [PATCH 16/16] Remove online with italic and bold syntax We fixed some issues without oneline option. Add unit tests. Fix #172 --- syntax/markdown.vim | 12 ++++---- test/syntax.vader | 75 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/syntax/markdown.vim b/syntax/markdown.vim index 79e1a3c..67043a1 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -42,12 +42,12 @@ if has('conceal') endif "additions to HTML groups -syn region htmlItalic start="\\\@