lervag / wiki.vim

A wiki plugin for Vim
MIT License
660 stars 69 forks source link

[REQ] transform TOC url #379

Open step- opened 2 months ago

step- commented 2 months ago

Hi, I use CommonMark in my published documents, which I edit with wiki.vim. I couldn't find a way to transform the link URL that :WikiTocGenerate makes, so I kindly request some way to do such transformation. I'm trying to fix the following issue. In CommonMark (therefore on GitHub and other sites that base their markdown flavor on CommonMark) this is not recognized as a markdown link:

*Contents*

* [Readme](#Readme)
    * [Debugging HTML](#Readme#Debugging HTML)

but this is:

*Contents*

* [Readme](#Readme)
    * [Debugging HTML](<#Readme#Debugging HTML>)               **within angle brackets**

visual example at CommonMark Dingus page

:WikiTocGenerate creates the first markdown block above. I would like to create the second one instead, so when I publish the TOC (not only on GitHub), the intended links turn out as such.

I do realize that if the URL is wrapped in angle brackets then wiki.vim won't be able to follow the link, and that is a problem. But for now I'm more interested in publishing online than navigating the markdown source, because I can also comfortably jump through the document with other vim commands. Thanks for your consideration.

lervag commented 2 months ago

Thanks; I'll look into this. I believe this should already be possible, but I will need to check it. If it is possible, I'll explain how; else I'll look into how I can add it.

lervag commented 2 months ago

Notice, though: The url will work if you use url encoding. I.e.:

*Contents*

* [Readme](#Readme)
    * [Debugging HTML](#Readme#Debugging%20HTML)
lervag commented 2 months ago

If you are in a rush, then I'd advice to look into g:wiki_link_creation and the url_transform key. See also :help wiki-advanced-config-2 for an example. But you are right - this is not affective for the toc generation. It probably should be, so I'll look into it when I get the time.

lervag commented 2 months ago

Oh, and finally: there are third-party tools for generating toc's for markdown files. In the meantime, I think you should consider using one of those. They are actually very good. For instance, see

Both of these can be used with the plugin https://github.com/stevearc/conform.nvim, which makes it quite convenient.

step- commented 2 months ago

Thank you for looking into this. If the URL can work with URL encoding that's a good alternative to angle brackets. The question remains, how to transform the URL in a TOC. I do use g:wiki_link_creation, so I was hoping it would work for TOC as well, but as you also say, it doesn't.

lervag commented 2 months ago

I do use g:wiki_link_creation, so I was hoping it would work for TOC as well, but as you also say, it doesn't.

I'll look into this. It may be straightforward, which means I will get it done relatively fast. But I need to think it through first - perhaps it makes sense to have a further option for this. TOCs are basically links with only anchors, so we need a proper transform of the anchors themselves. This will also require a similar resolve of the anchors. And the default anchor handling in wiki.vim is not really consistent with the standard Markdown or CommonMark spec.