Hi!
Is there an option to automatically add anchor link inside <h> tags just like it is done on documentation sites? If there is no such an option how can I do it with an extension?
For example this:
(new showdown.Converter()).makeHtml(' # Some header ');
Would produce this:
<h1 id="someheader">Some header <a href="#someheader">link</a></h1>
Or this:
<h1 id="someheader"><a href="#someheader">Some header link</a></h1>
I guess it would be a good feature to have.
You can use an output extension to accomplish this (see fiidle)
showdown.extension('headerlink', function() {
return [{
type: 'output',
regex: /(<h(\d) id="(.+)">(.+?))(<\/h\2>)/g,
replace: function (wm, g1, g2, id, g4, g5) {
return g1 + ' <a href="#' + id + '">link</a>' + g5;
}
}];
});
Most helpful comment
You can use an output extension to accomplish this (see fiidle)