EddyLuten / mkdocs-alias-plugin

An MkDocs plugin allowing links to your pages using a custom alias
MIT License
12 stars 2 forks source link

render anchor title instead of page title #8

Closed usulpt closed 5 months ago

usulpt commented 5 months ago

hello!

been using the plugin and it works great, however when I use anchors within the aliases, the rendered title is always for the main page and not for the anchor itself. is it possible to render the anchor title instead?

thank you! Jorge

EddyLuten commented 5 months ago

Hi Jorge, thanks for filing this issue! This could certainly be accomplished on a technical level, though it would have to be an opt-in feature configured through mkdocs.yml since it would change the existing behavior, and I don't want to break the plugin for other users.

I'll take a look at implementing it, though I'm not sure when I'll get to it. For now, as a workaround, I suggest using custom titles:

[[the-alias#anchor|Custom Title]]
usulpt commented 5 months ago

yeah, that's exactly what I've been doing for now, but it would be a welcome addition for automation and fire-and-forget editing. still, just thought I'd make the suggestion :) cheers and kutgw, Jorge

EddyLuten commented 5 months ago

Alright, I figured I'd give it a whirl and implemented the feature today. After upgrading to version 0.8.0, you should be able to enable the config flag use_anchor_titles and begin pulling in titles from headings.

This will only work for anchors generated through Markdown headings, which should be fine for most cases since embedded HTML is a bit of an edge case anyway. Meaning that it won't work for other types of anchors, such as pure HTML anchors, e.g.: <a name="anchor">...

Let me know if this works for you. I'm already beginning to use it in my personal KB. Thanks for the feature suggestion!

usulpt commented 5 months ago

wow, didn't think you'd actually pick this up any time soon, so our productive builds can't be changed, but I've tested in in our test environment and it looks good, going to ship it in the next builds, thank you so much! :)