8000 Allow customization of header level of TOC by gpanders · Pull Request #629 · vimwiki/vimwiki · GitHub
[go: up one dir, main page]

Skip to content

Conversation

gpanders
Copy link

Instead of forcing the TOC to always be at header level 1, allow the
user to specify via the option g:vimwiki_toc_header_level what level
they want.

This defaults to 1, so if the user does nothing then the old behavior
will remain the same.

Closes #626.

Instead of forcing the TOC to always be at header level 1, allow the
user to specify via the option g:vimwiki_toc_header_level what level
they want.

This defaults to 1, so if the user does nothing then the old behavior
will remain the same.
@hq6 hq6 self-assigned this Mar 14, 2019
@hq6
Copy link
Contributor
hq6 commented Mar 14, 2019

For posterity, can you provide the files you tested this with, and the procedures you used to test?

@gpanders
Copy link
Author

~/.vimrc:

let g:vimwiki_toc_header_level = 3

In a new file called index.wiki, write the following:

= Foo =
    * Test

== Bar ==
    * Test

Run :VimwikiTOC. Expected output should be:

=== Contents ===
    - [[#Foo|Foo]]
        - [[#Foo#Bar|Bar]]

Run :Vimwiki2HTML. Verify that the header under <div id="Contents" class="toc"> is <h3>.

If let g:vimwiki_toc_header_level is not specified, then the expected output is

= Contents =
    - [[#Foo|Foo]]
        - [[#Foo#Bar|Bar]]

as before, and the resulting HTML will have an <h1> header.

@ranebrown
Copy link
Contributor

I like this change. The only issue I see is that the TOC is still inserted at the top of the file. This most likely doesn't make sense if using a header level other than 1 (you probably don't want to end up with H3 for the TOC followed by an H1 header for something else).

It does work to manually move the TOC to a desired location and then updates work on the that location. Any ideas on a better way to handle this?

@gpanders
Copy link
Author

I think having the TOC inserted at the top by default is fine, since there is nothing that says an h3 or h2 cannot precede an h1. My motivation for doing this was actually because I wanted the TOC at the top, but I didn't want the "Contents" header to be the same size/boldface as my "actual" headers.

In the case that a user wants the TOC somewhere else in their document, they can manually initialize it wherever they want, as you said.

@ranebrown
Copy link
Contributor

Makes sense. I think it would be useful to have a command that inserts the TOC at the current cursor position (or something similar) but that can be left for another day. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0