File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed
Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,19 @@ Fenced code block languages ~
287287<
288288 Default is "['c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini']".
289289
290+ *g:vim_markdown_highlight_with_sed*
291+ - 'g:vim_markdown_highlight_with_sed'
292+
293+ Vim-markdown needs to search all fenced code blocks for the filetypes to
294+ highlight. The default code uses vim's builtin regex engine which is slow
295+ dealing with large markdown documents. Enabling this option would use
296+ command line utility 'sed' for searching. It's expected to improve performance
297+ around 10x.
298+ >
299+ let g:vim_markdown_highlight_with_sed = 1
300+ <
301+ Default is '0'.
302+
290303-------------------------------------------------------------------------------
291304 *vim-markdown-follow-named-anchors*
292305Follow named anchors ~
Original file line number Diff line number Diff line change @@ -787,10 +787,19 @@ function! s:MarkdownHighlightSources(force)
787787 " Syntax highlight source code embedded in notes.
788788 " Look for code blocks in the current file
789789 let filetypes = {}
790- for line in getline (1 , ' $' )
791- let ft = matchstr (line , ' ```\s*\zs[0-9A-Za-z_+-]*\ze.*' )
792- if ! empty (ft ) && ft !~ ' ^\d*$' | let filetypes[ft ] = 1 | endif
793- endfor
790+
791+ if get (g: , ' vim_markdown_highlight_with_sed' , 0 )
792+ let l: ft_lines = systemlist (' sed -n ' . " '" . ' /^[[:space:]]*```[[:space:]]*\([0-9A-Za-z_+-]*\).*$/s//\1/p' . " '" , bufnr ())
793+ for ft in l: ft_lines
794+ if ! empty (ft ) && ft !~ ' ^\d*$' | let filetypes[ft ] = 1 | endif
795+ endfor
796+ else
797+ for line in getline (1 , ' $' )
798+ let ft = matchstr (line , ' ```\s*\zs[0-9A-Za-z_+-]*\ze.*' )
799+ if ! empty (ft ) && ft !~ ' ^\d*$' | let filetypes[ft ] = 1 | endif
800+ endfor
801+ endif
802+
794803 if ! exists (' b:mkd_known_filetypes' )
795804 let b: mkd_known_filetypes = {}
796805 endif
You can’t perform that action at this time.
0 commit comments