From 8ef054d120231c5e8d6be73d02687d80ec423ee4 Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Tue, 23 Feb 2021 09:02:36 -0800 Subject: [PATCH 1/4] Never indent first level headings --- plugin/markdown-toc.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugin/markdown-toc.vim b/plugin/markdown-toc.vim index 73920f4..6e05587 100644 --- a/plugin/markdown-toc.vim +++ b/plugin/markdown-toc.vim @@ -34,7 +34,7 @@ function! s:FindHeaders() endfunction function! s:HeadingLevel(header) - let l:delim = split(a:header, " ")[0] + let l:delim = split(a:header, " ")[0] if(l:delim[0] == "=") return 1 elseif(l:delim[0] == "-") @@ -63,7 +63,12 @@ function! s:GenerateMarkdownTOC() let l:levelsStack[-1] = l:num + 1 let l:previousLevel = l:headingLevel - let l:formattedLine = repeat("\t", l:headingLevel - g:mdtoc_starting_header_level) . l:num . ". [" . sectionName . "](#" . sectionId . ")" + if(l:headingLevel == 1) + let l:formattedLine = repeat("", l:headingLevel - g:mdtoc_starting_header_level) . l:num . "[" . sectionName . "](#" . sectionId . ")" + else + let l:formattedLine = repeat("\t", l:headingLevel - g:mdtoc_starting_header_level) . l:num . "[" . sectionName . "](#" . sectionId . ")" + endif + put =l:formattedLine endfor endfunction From dd3ad4e92c626d7744474efe25304b0f9da1bd4c Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Tue, 23 Feb 2021 09:19:46 -0800 Subject: [PATCH 2/4] Allow bullets to be customizable --- plugin/markdown-toc.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/markdown-toc.vim b/plugin/markdown-toc.vim index 6e05587..a4ada1c 100644 --- a/plugin/markdown-toc.vim +++ b/plugin/markdown-toc.vim @@ -1,6 +1,9 @@ if !exists("g:mdtoc_starting_header_level") let g:mdtoc_starting_header_level = 2 endif +if !exists("g:mdtoc_number_headers") + let g:mdtoc_number_headers = 1 +endif function! s:HeaderSearchRegex() if(g:mdtoc_starting_header_level == 1) @@ -62,11 +65,16 @@ function! s:GenerateMarkdownTOC() let l:num = l:levelsStack[-1] let l:levelsStack[-1] = l:num + 1 let l:previousLevel = l:headingLevel + if(g:mdtoc_number_headers == 1) + let l:bullet = l:num . ". " + else + let l:bullet = "- " + endif if(l:headingLevel == 1) - let l:formattedLine = repeat("", l:headingLevel - g:mdtoc_starting_header_level) . l:num . "[" . sectionName . "](#" . sectionId . ")" + let l:formattedLine = repeat("", l:headingLevel - g:mdtoc_starting_header_level) . l:bullet . "[" . sectionName . "](#" . sectionId . ")" else - let l:formattedLine = repeat("\t", l:headingLevel - g:mdtoc_starting_header_level) . l:num . "[" . sectionName . "](#" . sectionId . ")" + let l:formattedLine = repeat("\t", l:headingLevel - g:mdtoc_starting_header_level) . l:bullet . "[" . sectionName . "](#" . sectionId . ")" endif put =l:formattedLine From 885f356e8f3dd5ab99a7ee562aac7a42bd2214d8 Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Tue, 23 Feb 2021 09:26:43 -0800 Subject: [PATCH 3/4] Allow indent to be customizable --- plugin/markdown-toc.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/markdown-toc.vim b/plugin/markdown-toc.vim index a4ada1c..047d139 100644 --- a/plugin/markdown-toc.vim +++ b/plugin/markdown-toc.vim @@ -4,6 +4,9 @@ endif if !exists("g:mdtoc_number_headers") let g:mdtoc_number_headers = 1 endif +if !exists("g:mdtoc_indent") + let g:mdtoc_indent = "\t" +endif function! s:HeaderSearchRegex() if(g:mdtoc_starting_header_level == 1) @@ -74,7 +77,7 @@ function! s:GenerateMarkdownTOC() if(l:headingLevel == 1) let l:formattedLine = repeat("", l:headingLevel - g:mdtoc_starting_header_level) . l:bullet . "[" . sectionName . "](#" . sectionId . ")" else - let l:formattedLine = repeat("\t", l:headingLevel - g:mdtoc_starting_header_level) . l:bullet . "[" . sectionName . "](#" . sectionId . ")" + let l:formattedLine = repeat(g:mdtoc_indent, l:headingLevel - g:mdtoc_starting_header_level) . l:bullet . "[" . sectionName . "](#" . sectionId . ")" endif put =l:formattedLine From db47782ab43b93914d3f24deaafbdc8aad3774be Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Tue, 23 Feb 2021 09:31:40 -0800 Subject: [PATCH 4/4] Add note in readme about new options --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 574479e..c05f467 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,16 @@ By default this plugin will not generate an entry for top level headers (`#` or let g:mdtoc_starting_header_level = 1 ``` +You can turn off the numbering of headings +```vimscript +let g:mdtoc_number_headers = 0 +``` + +And customize the indentation characters, e.g. to use spaces instead of the default tab +```vimscript +let g:mdtoc_indent = " " +``` + ## Example ```markdown