Skip to content

Generalize wiki#toc#gather_entries #288

@lervag

Description

@lervag

wiki#toc#gather_entries assumes ATX headers:

" Parse current header
let l:level = len(matchstr(l:line, '^#*'))
let l:header = matchlist(l:line, g:wiki#rx#header_items)[2]
let l:anchors[l:level] = l:header

wiki.vim is meant to be filetype agostic, thus this should be generalized to allow other formats, as suggested by @saccarosium in #287.

Proposal: Add an option g:wiki_toc_header_format to allow other header formats, e.g.:

*g:wiki_toc_header_format*
  Option to specify the header format used for parsing the table of contents.

  Possible values:

    atx ~
      Atx headers are probably the most common header type in Markdown files
      and look like this: >markdown

        # Header level 1

        ## Header level 2
<
    setext ~
      Setext headers are common in Markdown files and look like this: >markdown

        Header level 1
        ===

        Header level 2
        ---
<
    asciidoc ~
      AsciiDoc headers are used in AsciiDoc files. They look like this: >asciidoc

        = Document Title (level 0)

        == Level 1 Section title

        === Level 2 Section title
<

One problem with using a global option is that one may want wiki.vim to work with different filetypes. Thus, it should be possible to also override the global option in any relavant commands, e.g. WikiTocGenerate:

*<plug>(wiki-toc-generate)*
*WikiTocGenerate*
`:[range]WikiTocGenerate [header_format]
  Create/Update table of contents. The optional argument `header_format` allows
  to override the header format specified in |g:wiki_toc_header_format|.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions