Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #544 use sed for improving highting performance #553

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/vim-markdown.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,19 @@ Fenced code block languages ~
<
Default is "['c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini']".

*g:vim_markdown_highlight_with_sed*
- 'g:vim_markdown_highlight_with_sed'

Vim-markdown needs to search all fenced code blocks for the filetypes to
highlight. The default code uses vim's builtin regex engine which is slow
dealing with large markdown documents. Enabling this option would use
command line utility 'sed' for searching. It's expected to improve performance
around 10x.
>
let g:vim_markdown_highlight_with_sed = 1
<
Default is '0'.

-------------------------------------------------------------------------------
*vim-markdown-follow-named-anchors*
Follow named anchors ~
Expand Down
17 changes: 13 additions & 4 deletions ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,19 @@ function! s:MarkdownHighlightSources(force)
" Syntax highlight source code embedded in notes.
" Look for code blocks in the current file
let filetypes = {}
for line in getline(1, '$')
let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*\ze.*')
if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
endfor

if get(g:, 'vim_markdown_highlight_with_sed', 0)
let l:ft_lines = systemlist('sed -n ' . "'" . '/^[[:space:]]*```[[:space:]]*\([0-9A-Za-z_+-]*\).*$/s//\1/p' . "'", bufnr())
for ft in l:ft_lines
if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
endfor
else
for line in getline(1, '$')
let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*\ze.*')
if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
endfor
endif

if !exists('b:mkd_known_filetypes')
let b:mkd_known_filetypes = {}
endif
Expand Down