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.
This commit is contained in:
		| @@ -358,7 +358,7 @@ function! vimwiki#base#generate_links() | |||||||
|  |  | ||||||
|   let links_rx = '\m^\s*'.vimwiki#u#escape(vimwiki#lst#default_symbol()).' ' |   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 | endfunction | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -1015,14 +1015,14 @@ endfunction | |||||||
|  |  | ||||||
| " creates or updates auto-generated listings in a wiki file, like TOC, diary | " creates or updates auto-generated listings in a wiki file, like TOC, diary | ||||||
| " links, tags list etc. | " 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: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 | " - a:default_lnum is the line number where the new listing should be placed if | ||||||
| "   it's not already present | "   it's not already present | ||||||
| " - if a:create is true, it will be created if it doesn't exist, otherwise it | " - if a:create is true, it will be created if it doesn't exist, otherwise it | ||||||
| "   will only be updated if it already exists | "   will only be updated if it already exists | ||||||
| function! vimwiki#base#update_listing_in_buffer(strings, start_header, | 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 |   " Vim behaves strangely when files change while in diff mode | ||||||
|   if &diff || &readonly |   if &diff || &readonly | ||||||
|     return |     return | ||||||
| @@ -1031,7 +1031,8 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, | |||||||
|   " check if the listing is already there |   " check if the listing is already there | ||||||
|   let already_there = 0 |   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*$' |         \ '__Header__', a:start_header, '') .'\s*$' | ||||||
|  |  | ||||||
|   let start_lnum = 1 |   let start_lnum = 1 | ||||||
| @@ -1083,7 +1084,7 @@ function! vimwiki#base#update_listing_in_buffer(strings, start_header, | |||||||
|  |  | ||||||
|   " write new listing |   " write new listing | ||||||
|   let new_header = whitespaces_in_first_line |   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, '') |         \ '__Header__', a:start_header, '') | ||||||
|   keepjumps call append(start_lnum - 1, new_header) |   keepjumps call append(start_lnum - 1, new_header) | ||||||
|   let start_lnum += 1 |   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()).' ' |   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 | endfunction | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -287,7 +287,7 @@ function! vimwiki#diary#generate_diary_section() | |||||||
|   if vimwiki#path#is_equal(current_file, diary_file) |   if vimwiki#path#is_equal(current_file, diary_file) | ||||||
|     let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)' |     let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)' | ||||||
|     call vimwiki#base#update_listing_in_buffer(s:format_diary(), |     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 |   else | ||||||
|     echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!' |     echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!' | ||||||
|   endif |   endif | ||||||
|   | |||||||
| @@ -1078,7 +1078,7 @@ function! s:process_tag_h(line, id) | |||||||
|  |  | ||||||
|     else |     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 |     endif | ||||||
|  |  | ||||||
|   | |||||||
| @@ -329,7 +329,7 @@ function! vimwiki#tags#generate_tags(...) abort | |||||||
|         \ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' ' |         \ .vimwiki#u#escape(vimwiki#lst#default_symbol()).' ' | ||||||
|         \ .vimwiki#vars#get_syntaxlocal('rxWikiLink').'$\)' |         \ .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 | endfunction | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -171,6 +171,7 @@ function! s:read_global_settings_from_user() | |||||||
|         \ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, |         \ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, | ||||||
|         \ 'table_mappings': {'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': {'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}, |         \ 'url_maxsave': {'type': type(0), 'default': 15, 'min': 0}, | ||||||
|         \ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, |         \ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, | ||||||
|         \ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, |         \ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, | ||||||
|   | |||||||
| @@ -2872,6 +2872,15 @@ appropriate word in your mother tongue like this: > | |||||||
| The default is 'Contents'. | 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* | *g:vimwiki_map_prefix* | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user