Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions plugin/markdown-toc.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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
if !exists("g:mdtoc_indent")
let g:mdtoc_indent = "\t"
endif

function! s:HeaderSearchRegex()
if(g:mdtoc_starting_header_level == 1)
Expand Down Expand Up @@ -34,7 +40,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] == "-")
Expand Down Expand Up @@ -62,8 +68,18 @@ 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:bullet . "[" . sectionName . "](#" . sectionId . ")"
else
let l:formattedLine = repeat(g:mdtoc_indent, l:headingLevel - g:mdtoc_starting_header_level) . l:bullet . "[" . sectionName . "](#" . sectionId . ")"
endif

let l:formattedLine = repeat("\t", l:headingLevel - g:mdtoc_starting_header_level) . l:num . ". [" . sectionName . "](#" . sectionId . ")"
put =l:formattedLine
endfor
endfunction
Expand Down