commit bb40826def8c5c019704ad4450e7317c0fc8bdb8
parent 54d1a997d91198ddf9622feedc9f0add4e76e169
Author: Greg Anders <greande@sandia.gov>
Date: Wed, 13 Mar 2019 08:28:22 -0600
Allow customization of header level of TOC
Instead of forcing the TOC to always be at header level 1, allow the
user to specify via the option g:vimwiki_toc_header_level what level
they want.
This defaults to 1, so if the user does nothing then the old behavior
will remain the same.
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
@@ -1875,7 +1876,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
@@ -1078,7 +1078,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
@@ -171,6 +171,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
@@ -2873,6 +2873,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