mzlogin / vim-markdown-toc

A vim 7.4+ plugin to generate table of contents for Markdown files.
http://www.vim.org/scripts/script.php?script_id=5460
MIT License
613 stars 59 forks source link

Generate ordered list of contents #23

Closed stooj closed 7 months ago

stooj commented 7 years ago

I find a numerically ordered toc more useful than an unordered list; the document has an order and sections are usually arranged in order.

Could we have an option to generate an ordered list instead of an unordered one?

eg:

1. Features
2. Installation
3. Usage
    1. Generate table of contents
    2. Update existing table of contents
mzlogin commented 7 years ago

Thanks for your suggestion, I'll think about it.

barrymw commented 7 years ago

This can be achieved by adding the following line in $HOME/.vimrc

let g:vmt_list_item_char = '1.'

It is strictly not a single character, but the code doesn't actually care.

Then when you invoke :GenTocGFM in vim:


<!-- vim-markdown-toc GFM -->

1. [Description](#description)
1. [Setup](#setup)
    1. [What helloworld affects](#what-helloworld-affects)
stooj commented 7 years ago

Nice. That's a good workaround for now, but although it's great for the html output, quite a lot of staff read the plain text versions, and an auto-incrementing list would be preferable.

Thanks for the workaround, @barrymw

weibeld commented 1 year ago

The proposed workaround doesn't work for nested lists as vim-markdown-toc indents nested items by exactly two spaces, however, GitHub Flavoured Markdown (GFM) requires the list marker of a nested list to be exactly under the start of the text of the parent item or farther to the right of it (see e.g. here). This is 2 spaces for single-character markers (e.g. - or *), but it's 3 spaces for two-digits markers like 1..

For example, vim-markdown-toc would generate the following:

- Item 1
  - Subitem 1
- Item2

And:

1. Item 1
  1. Subitem 1
1. Item 2

The unordered list if valid GFM, however, the ordered list is not and is rendered incorrectly. To be valid GFM, it would need to be:

1. Item 1
   1. Subitem 1
1. Item 2
weibeld commented 7 months ago

EDIT to above comment: the number of spaces to indent child items with can actually be specified by setting g:vmt_list_indent_text as explained in the docs.

For example:

:let g:vmt_list_indent_text = '   '

The above causes child items to be indented by 3 spaces (default is a tab or shiftwidth number of spaces if expandtab is set).

In that way, it should be possible to correctly generate any type of ordered nested list.

This issue should probably be closed.

mzlogin commented 7 months ago

@weibeld Thanks for your comment.