Skip to content

Commit 582eb8a

Browse files
committed
Merge branch 'footnotes-fix-confused-for-link-reference' into all-footnote-fixes
2 parents a0de7d8 + 740b987 commit 582eb8a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/inlines.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,13 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
11411141
!opener->inl_text->next->next) {
11421142
cmark_chunk *literal = &opener->inl_text->next->as.literal;
11431143
if (literal->len > 1 && literal->data[0] == '^') {
1144+
1145+
// Before we got this far, the `handle_close_bracket` function may have
1146+
// advanced the current state beyond our footnote's actual closing
1147+
// bracket, ie if it went looking for a `link_label`.
1148+
// Let's just rewind the subject's position:
1149+
subj->pos = initial_pos;
1150+
11441151
inl = make_simple(subj->mem, CMARK_NODE_FOOTNOTE_REFERENCE);
11451152
inl->as.literal = cmark_chunk_dup(literal, 1, literal->len - 1);
11461153
inl->start_line = inl->end_line = subj->line;

test/regression.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ Pull request #128 - Buffer overread in tables extension
272272

273273
Footnotes may be nested inside other footnotes.
274274

275-
276275
```````````````````````````````` example footnotes
277276
This is some text. It has a citation.[^citation]
278277

@@ -292,3 +291,25 @@ This is some text. It has a citation.[^citation]
292291
</ol>
293292
</section>
294293
````````````````````````````````
294+
295+
Footnotes are similar to, but should not be confused with, link references
296+
297+
```````````````````````````````` example footnotes
298+
This is some text. It has two footnotes references, side-by-side without any spaces,[^footnote1][^footnote2] which are definitely not link references.
299+
300+
[^footnote1]: Hello.
301+
302+
[^footnote2]: Goodbye.
303+
.
304+
<p>This is some text. It has two footnotes references, side-by-side without any spaces,<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup><sup class="footnote-ref"><a href="#fn2" id="fnref2">2</a></sup> which are definitely not link references.</p>
305+
<section class="footnotes">
306+
<ol>
307+
<li id="fn1">
308+
<p>Hello. <a href="#fnref1" class="footnote-backref">↩</a></p>
309+
</li>
310+
<li id="fn2">
311+
<p>Goodbye. <a href="#fnref2" class="footnote-backref">↩</a></p>
312+
</li>
313+
</ol>
314+
</section>
315+
````````````````````````````````

0 commit comments

Comments
 (0)