When a footnote reference immediately follows a link, the output merely copies out the input.
I am guessing that [...][^...] gets treated as [...][...] with no link in the second square brackets and hence remains unprocessed.
This imho incorrect handling occurs in the github window albiet a bit differently. Here the link is rendered but footnote is just gobbled up (which is even worse). See this at the very bottom!
The code:
const options = {
footnotes: true,
gfm: true
};
const processor = unified()
.use(parse, options)
.use(remark2rehype)
.use(html)
fs.readFile('sample.md', 'utf8', function(err, data) {
processor.process(data)
.then(function(out) {
fs.writeFile('sample.html', out, 'utf8', function(err){
if (err) throw err;
return;
})
})
.catch(function(err) {
console.log(err);
});
});
Input (sample.md)
[foo][^foo]
[foo]: example.com
[^foo]: bar
<p><a href="example.com">foo</a><sup id="fnref-foo"><a href="#fn-foo" class="footnote-ref">foo</a></sup></p>
<div class="footnotes">
<hr>
<ol>
<li id="fn-foo">bar<a href="#fnref-foo" class="footnote-backref">↩</a></li>
</ol>
</div>
<p>[foo][^foo]</p>
These inputs actually work:
[foo][][^foo]
[foo][foo][^foo]
Here is what Github does (which I also think is incorrect):
Original: foo [foo][^foo] // Footnote is just gobbled up!
Bonus 1: foo[^foo] [foo][][^foo]
Bonus 2: foo[^foo] [foo][foo][^foo]
The references and definitions are being parsed as expected https://astexplorer.net/#/gist/b9c5cb02ceb8b9b927649d053a0fbf45/c288e456e08a2583ecf67f60d4d6527e5a3e08d1
Moving this to remark-rehype which handles the HTML transform.
Hmm, I’m not so sure that [foo][^bar] is one link reference (with content foo and label ^bar or bar), which we currently parse to. It’s a bit vague (as footnotes are a non-standard feature).
My thinking goes that I’d argue [^foo]: bar is definitely a footnote definition and not a URL definitions. Which leads me to believe that, if footnotes are enabled, [^ can’t reference a URL definition.
@CxRes for a quick fix, I suggest against using shortcut references ([foo] instead of [foo][] or [bar][foo]).
@wooorm Its time to explain how I am coming up with these edge cases. It is not that I would have written such a shortcut reference myself. I am stumbling on issues, here and elsewhere, as I am testing out samples written by others.
Specifically, I am trying to implement a modified version of tufte-css for markdown using luhmann/tufte-markdown. The trouble is luhmann/tufte-markdown in turn relies on the conventions of jez/tufte-pandoc-css which are meant for pandoc. And as we discussed elsewhere, there are deviations in pandoc syntax from cm/gfm and in fact problems in remark tufte-css implementation can be seen in the tests itself (I'll be opening more issues with @luhmann very soon).
Moving this back to remarkjs/remark as due to my thinking in the second paragraph of my previous comment https://github.com/remarkjs/remark-rehype/issues/12#issuecomment-488687513