commit c8d09d7c9e1359c618b96e72abab90daefd7aa3a
parent e0f4ab8c5e59b92218e7479f18f6e4d58eaa4cdb
Author: Rane Brown <ranebrown@users.noreply.github.com>
Date: Mon, 18 Mar 2019 17:20:30 -0600
Merge pull request #629 from gpanders/dev
Allow customization of header level of TOC
Diffstat:
6 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
@@ -358,7 +358,7 @@ function! vimwiki#base#generate_links()
let links_rx = '\m^\s*'.vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
- call vimwiki#base#update_listing_in_buffer(lines, 'Generated Links', links_rx, line('$')+1, 1)
+ call vimwiki#base#update_listing_in_buffer(lines, 'Generated Links', links_rx, line('$')+1, 1, 1)
endfunction
@@ -1015,14 +1015,14 @@ endfunction
" creates or updates auto-generated listings in a wiki file, like TOC, diary
" links, tags list etc.
-" - the listing consists of a level 1 header and a list of strings as content
+" - the listing consists of a header and a list of strings as content
" - a:content_regex is used to determine how long a potentially existing list is
" - a:default_lnum is the line number where the new listing should be placed if
" it's not already present
" - if a:create is true, it will be created if it doesn't exist, otherwise it
" will only be updated if it already exists
function! vimwiki#base#update_listing_in_buffer(strings, start_header,
- \ content_regex, default_lnum, create)
+ \ content_regex, default_lnum, header_level, create)
" Vim behaves strangely when files change while in diff mode
if &diff || &readonly
return
@@ -1031,7 +1031,8 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
" check if the listing is already there
let already_there = 0
- let header_rx = '\m^\s*'.substitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'),
+ let header_level = 'rxH' . a:header_level . '_Template'
+ let header_rx = '\m^\s*'.substitute(vimwiki#vars#get_syntaxlocal(header_level),
\ '__Header__', a:start_header, '') .'\s*$'
let start_lnum = 1
@@ -1083,7 +1084,7 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header,
" write new listing
let new_header = whitespaces_in_first_line
- \ . s:safesubstitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'),
+ \ . s:safesubstitute(vimwiki#vars#get_syntaxlocal(header_level),
\ '__Header__', a:start_header, '')
keepjumps call append(start_lnum - 1, new_header)
let start_lnum += 1
@@ -1881,7 +1882,13 @@ function! vimwiki#base#table_of_contents(create)
let links_rx = '\m^\s*'.vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
- call vimwiki#base#update_listing_in_buffer(lines, toc_header_text, links_rx, 1, a:create)
+ call vimwiki#base#update_listing_in_buffer(
+ \ lines,
+ \ toc_header_text,
+ \ links_rx,
+ \ 1,
+ \ vimwiki#vars#get_global('toc_header_level'),
+ \ a:create)
endfunction
diff --git a/autoload/vimwiki/diary.vim b/autoload/vimwiki/diary.vim
@@ -287,7 +287,7 @@ function! vimwiki#diary#generate_diary_section()
if vimwiki#path#is_equal(current_file, diary_file)
let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)'
call vimwiki#base#update_listing_in_buffer(s:format_diary(),
- \ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1)
+ \ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1, 1)
else
echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!'
endif
diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim
@@ -1098,7 +1098,7 @@ function! s:process_tag_h(line, id)
else
- let h_part = '<div id="'.h_id.'" class="toc"><h1 id="'.h_id.'"'
+ let h_part = '<div id="'.h_id.'" class="toc"><h'.h_level.' id="'.h_id.'"'
endif
diff --git a/autoload/vimwiki/tags.vim b/autoload/vimwiki/tags.vim
@@ -329,7 +329,7 @@ function! vimwiki#tags#generate_tags(...) abort
\ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
\ .vimwiki#vars#get_syntaxlocal('rxWikiLink').'$\)'
- call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx, line('$')+1, 1)
+ call vimwiki#base#update_listing_in_buffer(lines, 'Generated Tags', links_rx, line('$')+1, 1, 1)
endfunction
diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim
@@ -172,6 +172,7 @@ function! s:read_global_settings_from_user()
\ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'table_mappings': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'toc_header': {'type': type(''), 'default': 'Contents', 'min_length': 1},
+ \ 'toc_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6},
\ 'url_maxsave': {'type': type(0), 'default': 15, 'min': 0},
\ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt
@@ -2916,6 +2916,15 @@ The default is 'Contents'.
------------------------------------------------------------------------------
+*g:vimwiki_toc_header_level*
+
+The header level of the Table of Contents (see |vimwiki-toc|). Valid values
+are from 1 to 6.
+
+The default is 1.
+
+
+------------------------------------------------------------------------------
*g:vimwiki_map_prefix*
A string which specifies the prefix for all global mappings (and some local