jghauser / follow-md-links.nvim

Easily follow markdown links with this neovim plugin
GNU General Public License v3.0
140 stars 15 forks source link

Support for following anchor links #9

Open paanvaannd opened 2 years ago

paanvaannd commented 2 years ago

First off: thanks for the great plugin! Glad to have this functionality independent of other Markdown plugins laden with more features than what I need.

The only thing(s?*) I think I'm missing from this plugin is support for following Markdown anchor links as outlined here.

Concrete case: I created a journal file (2022-07-11.md) that outlined what I was learning in Lua one day and another file for notes on Lua (lua.md) within the same directory. Within lua.md, there is a section header by the name "Tables," which should be addressable through the aforementioned anchor link schema as lua.md#tables. However, the plugin no longer follows the link to lua.md at all, let alone place the cursor at the specified header.

* I'm unsure if this is a separate feature or just an extension of the plain anchor link schema above, but Pandoc-flavored Markdown allows for addressing arbitrary chunks of text through the use of tagged spans. This extension would literally fulfill all my needs if it were possible to address those tagged span anchors as well.

P.S. I'd be happy to contribute how I can, which for now would probably just be testing until I learn enough Lua.

e: this documentation about header links in Markdown may also be of some use, I think

jghauser commented 2 years ago

Hey! Thanks for your interest and kinds words! Yeah, internal links of all sorts are currently missing and definitely something that would make sense for the plugin. I can only support features that are supported by the treesitter parser, so I'll have to check regarding the pandoc specific stuff.

I'm also a bit busy at the moment, so I'm not sure when I'll get around to taking a stab at this. Do any of the more feature-rich plugins you mention support what you want? Might lessen the necessary work a bit if we can take some inspirations from them... :)

paanvaannd commented 2 years ago

Do any of the more feature-rich plugins you mention support what you want? Might lessen the necessary work a bit if we can take some inspirations from them... :)

Excellent point! I did a bit of digging and here is what I found within each that may help on this issue in particular and potentially with internal linking in general.

I can't find anything concrete among the other plugins for bracketed span support (mainly mkdnflow, vim-pandoc-syntax, & vimwiki).

That said, there is vim-pandoc-syntax issue vim-pandoc/vim-pandoc-syntax#259 concerning the same request here as well as the related vim-pandoc/vim-pandoc-syntax#236 issue for fenced div blocks, Within the latter issue, there is a reference to Pandoc issue jgm/pandoc#5461 in which a Pandoc dev mentions work on implementing a CommonMark parser that supports a lot/all of Pandoc's syntax, including bracketed spans. The last link there is to a search within the CommonMark parser repo for "bracketed" which brings up a lot of results for bracketed spans within the code & documentation. However, the code is mainly in Haskell and I don't yet know enough of Lua or any of Haskell to try to port the code there to Lua.

Vimwiki supports anchor links (see "vimwiki-anchors" heading) for headers as usual as well as for tags and bold text. I'm not sure whether this only applies to Vimwiki's custom filetype or if it extends to Markdown as well, but it may be worth combing through the Vimscript to find how they handle linking to bold text or tags as there may be some function that can be generalized to link to any arbitrary delimiters instead of just bold text or tags as they have implemented.

Finally, mkdwnflow would be great to reference for handling internal links/anchors since it's also written in Lua and explicitly deals with Markdown. Concerning bracketed spans, I actually opened the related issue jakewvincent/mkdnflow.nvim#64 within that repo as well, so if there is any action there, it may be easy to port here.

jghauser commented 2 years ago

Thanks a lot for doing all the research! I'm gonna have a look at this in the next days! :)

jghauser commented 2 years ago

Sorry for taking so long to get back to you! I've had a look at the info you provided, and it looks like none of them use treesitter to implement link detection. It's still nothing major to implement this here, but right now I'm prioritising another project of mine. I'd of course be very happy about any PRs!

adrian5 commented 2 years ago

If feasible, I think enabling anchored links to work like non-anchored ones (discarding the anchor part for now) would be a good intermediate step.

paanvaannd commented 2 years ago

Sorry for taking so long to get back to you!

No worries, @jghauser! We all get busy from time to time and this is something you're contributing on your own time (I presume), so any assistance at your convenience is appreciated.

I have been quite busy as well and unfortunately can't help with a PR at the moment myself as I know almost nothing about Lua or how to work with Treesitter, but it's something I'll start delving into in coming months if it's not already addressed by then

In the meantime, in case anyone wants a Lua-native solution that doesn't (to my knowledge) use Treesitter, mkdnflow has implemented bracketed spans recently!