From 4c2e13a2844a3df0af5280227cdaf7d3c63d7f30 Mon Sep 17 00:00:00 2001 From: EinfachToll Date: Fri, 18 Mar 2016 15:18:23 +0100 Subject: [PATCH] Skip preformatted and math text while scanning for headers Fix #191 --- autoload/vimwiki/base.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index f6f5772..94966c5 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1736,10 +1736,27 @@ endfunction " }}} " a:create == 0: update if TOC exists function! vimwiki#base#table_of_contents(create) " collect new headers + let is_inside_pre_or_math = 0 " 1: inside pre, 2: inside math, 0: outside let headers = [] let headers_levels = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0]] for lnum in range(1, line('$')) let line_content = getline(lnum) + if (is_inside_pre_or_math == 1 && line_content =~# g:vimwiki_rxPreEnd) || + \ (is_inside_pre_or_math == 2 && line_content =~# g:vimwiki_rxMathEnd) + let is_inside_pre_or_math = 0 + continue + endif + if is_inside_pre_or_math > 0 + continue + endif + if line_content =~# g:vimwiki_rxPreStart + let is_inside_pre_or_math = 1 + continue + endif + if line_content =~# g:vimwiki_rxMathStart + let is_inside_pre_or_math = 2 + continue + endif if line_content !~# g:vimwiki_rxHeader continue endif