cmaas / markdown-it-table-of-contents

A table of contents plugin for Markdown-it
MIT License
99 stars 33 forks source link

Rule link_open #42

Closed seahindeniz closed 3 years ago

seahindeniz commented 5 years ago

Content links are not affected by the link_open rule whether is defined before .use or after.

md.renderer.rules.link_open = () => `<a class="sg-text--link sg-text--bold sg-text--blue-dark">`;

Expected result:

<ul>
  <li>
    <a href="#h1-heading" class="sg-text--link sg-text--bold sg-text--blue-dark">h1 Heading</a>
  </li>
</ul>

Actual result

<ul>
  <li>
    <a href="#h1-heading">h1 Heading</a>
  </li>
</ul>
Morgul commented 5 years ago

Yeah, this hit me as well. I'm trying to use this on a Nuxt.js site, and nuxt requires you to use <nuxt-link> tags instead of <a> tags so it's routing logic can handle some things for you. There's no way to make the links generate correctly without either being able to override the tag used for the links, or intercepting them with rules.link_open (Which is how I capture all the rest of the links on the page).

martinlissmyr commented 5 years ago

A PR with a fix would be most welcome! :)