Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQ] transform TOC url #379

Open
step- opened this issue Aug 27, 2024 · 6 comments
Open

[REQ] transform TOC url #379

step- opened this issue Aug 27, 2024 · 6 comments

Comments

@step-
Copy link
Contributor

step- commented Aug 27, 2024

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
Copy link
Owner

lervag commented Aug 27, 2024

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
Copy link
Owner

lervag commented Aug 27, 2024

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

*Contents*

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

@lervag
Copy link
Owner

lervag commented Aug 27, 2024

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
Copy link
Owner

lervag commented Aug 27, 2024

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-
Copy link
Contributor Author

step- commented Aug 27, 2024

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
Copy link
Owner

lervag commented Aug 27, 2024

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.

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

No branches or pull requests

2 participants