Skip to content

Commit

Permalink
remark-parse: fix support for image-like footnotes
Browse files Browse the repository at this point in the history
Previously, image-like footnotes (such as `Hello![^foo]`) were seen
as image references if `footnotes: true` was passed.  However, it
makes much more sense, as pointed out in GH-283, that they are
footnotes instead.  This commit makes that happen.

Closes GH-283.
  • Loading branch information
wooorm committed Jan 20, 2018
1 parent 549f9a5 commit d18f238
Show file tree
Hide file tree
Showing 4 changed files with 672 additions and 53 deletions.
12 changes: 7 additions & 5 deletions packages/remark-parse/lib/tokenize/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ function reference(eat, value, silent) {
queue = '';

/* Check whether we’re eating a footnote. */
if (
self.options.footnotes &&
type === T_LINK &&
value.charAt(index) === C_CARET
) {
if (self.options.footnotes && value.charAt(index) === C_CARET) {
/* Exit if `![^` is found, so the `!` will be seen as text after this,
* and we’ll enter this function again when `[^` is found. */
if (type === T_IMAGE) {
return;
}

intro += C_CARET;
index++;
type = T_FOOTNOTE;
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/input/footnote-without-space.text
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
foo[^abc] bar. foo[^xyz] bar

And some more tests for “image like” footnotes, related to:
<https://github.com/remarkjs/remark/issues/283>:

Hello[^footnote]
Hello![^footnote]
Hello! [^footnote]

[^abc]: Baz baz

[^xyz]: Baz

[^footnote]: Some definition.

0 comments on commit d18f238

Please sign in to comment.