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
609 stars 59 forks source link

include section the toc is under in the toc #57

Open PlasmaHH opened 5 years ago

PlasmaHH commented 5 years ago

Currently it looks like the plugin ignores all headings above the point where you insert it. This leads to the case that when it is inserted under a # heading and after the toc comes a ## heading, the generated markdown list starts with an indentation, which will not be rendered as part of the list. Therefore the plugin should have an option to also include all the headings that are before its insert point

mzlogin commented 5 years ago

Thanks for your suggestion.

Let me retell your scene,

# heading1-1

<-- you want to insert toc here

## heading2-1

# heading1-2

## heading2-2

is that right?

PlasmaHH commented 5 years ago

Yes, exactly. Though other positions should probably work too ;)

mzlogin commented 5 years ago

I think I get the drift. But I want to know, why don't you insert toc in the following two positions

<------------------- position 1

# heading1-1

## heading2-1

<------------------- position 2

# heading1-2

## heading2-2
PlasmaHH commented 5 years ago

This is just the style my/our readmes are constructed, for a bit more context imagine:

Project

TOC

## Abstract # Chapter 1 .... # Chapter 2 .... The documents basically have an introductionary level1 chapter that contains the toc as a part of the introduction. Btw. I found a hackish workaround, which relies on what maybe would be considered a bug by some. Putting `# Project` within html comments just after the toc makes it not displayed as text but parsed by the toc plugin. However this might be considered a bug in case it is expected to ignore things that would not be rendered. Also I am not sure if this works for all markdown renderers.
mzlogin commented 5 years ago

Hi~I add an option g:vmt_include_headings_before to support this.

So you can add let g:vmt_include_headings_before = 1 in your vimrc file now.

Could you please feedback your result? Thanks a lot!

PlasmaHH commented 5 years ago

Indeed it works as expected