vim-markdown-toc icon indicating copy to clipboard operation
vim-markdown-toc copied to clipboard

Generate ordered list of contents

Open stooj opened this issue 7 years ago • 4 comments

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

stooj avatar May 09 '17 04:05 stooj

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

mzlogin avatar May 09 '17 04:05 mzlogin

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)

barrymw avatar Oct 22 '17 00:10 barrymw

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

stooj avatar Oct 23 '17 09:10 stooj

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 avatar Jul 18 '23 15:07 weibeld

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.

weibeld avatar Apr 05 '24 09:04 weibeld

@weibeld Thanks for your comment.

mzlogin avatar Apr 07 '24 01:04 mzlogin