claudioc / jingo

Node.js based Wiki
MIT License
1.02k stars 183 forks source link

Links in headings cause incorrect TOC links #159

Open yazshel opened 8 years ago

yazshel commented 8 years ago

If I add this markdown to a wiki article:

{{TOC}}

# A heading containing [a link to an external site](http://www.externalsite.com/)

generates the following HTML (taken from the preview window):

<div id="content"><ul>
<li><a href="#a-heading-containing-a-link-to-an-external-site-http-www-externalsite-com-">A heading containing </a><a href="http://www.externalsite.com/">a link to an external site</a></li>
</ul>
<h1 id="a-heading-containing-a-link-to-an-external-site-http-www-externalsite-com-">A heading containing <a href="http://www.externalsite.com/">a link to an external site</a></h1>
</div>

While the link in the h1 was expected, I would expect clicking anywhere on the TOC entry should take me to that heading in the wiki article.

Maybe any links could be stripped from a heading when building its related TOC entry?

claudioc commented 8 years ago

Uh... there is a bug when rendering not in preview: a-heading-containing-a-link-to-an-external-site-http-www-externalsite-com- vs a-heading-containing--a-link-to-an-external-site--http---wwwexternalsitecom-- (the double -- is converted in a single - in the id. I will see if I can fix it

claudioc commented 8 years ago

As it turned out this is a problem of older version of Jingo. The current version (1.6.1) doesn't suffer of that problem :)

yazshel commented 8 years ago

Hi, sorry but I'm a bit confused - you seem to be talking about the IDs that get generated? This is not the issue - the issue is that the rendered TOC link contains: <a href="http://www.externalsite.com/">a link to an external site</a>

I would expect the "a link to an external site" text from the TOC link to still link to <a href="#a-heading-containing-a-link-to-an-external-site-http-www-externalsite-com-"> like the rest of the TOC entry.

I've verified just now that this is still a problem on the current master branch of your Jingo repository.

claudioc commented 8 years ago

Ah, I see what you mean. I was distracted by a different bug on the same context :D

And you're right, we should remove any link from any TOC entry. Reopening.