Skip to content

Commit 9eb8858

Browse files
authored
Merge pull request commonmark#234 from github/add-attributes-to-footnotes
Add data attributes for footnotes
2 parents d7e50f0 + b6e462f commit 9eb8858

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

src/html.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
6666

6767
cmark_strbuf_puts(html, "<a href=\"#fnref-");
6868
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
69-
cmark_strbuf_puts(html, "\" class=\"footnote-backref\">↩</a>");
69+
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a>");
7070

7171
if (node->footnote.def_count > 1)
7272
{
@@ -78,7 +78,7 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
7878
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
7979
cmark_strbuf_puts(html, "-");
8080
cmark_strbuf_puts(html, n);
81-
cmark_strbuf_puts(html, "\" class=\"footnote-backref\">↩<sup class=\"footnote-ref\">");
81+
cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩<sup class=\"footnote-ref\">");
8282
cmark_strbuf_puts(html, n);
8383
cmark_strbuf_puts(html, "</sup></a>");
8484
}
@@ -406,7 +406,7 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
406406
case CMARK_NODE_FOOTNOTE_DEFINITION:
407407
if (entering) {
408408
if (renderer->footnote_ix == 0) {
409-
cmark_strbuf_puts(html, "<section class=\"footnotes\">\n<ol>\n");
409+
cmark_strbuf_puts(html, "<section class=\"footnotes\" data-footnotes>\n<ol>\n");
410410
}
411411
++renderer->footnote_ix;
412412

@@ -435,7 +435,7 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
435435
cmark_strbuf_puts(html, n);
436436
}
437437

438-
cmark_strbuf_puts(html, "\">");
438+
cmark_strbuf_puts(html, "\" data-footnote-ref>");
439439
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
440440
cmark_strbuf_puts(html, "</a></sup>");
441441
}

test/extensions.txt

+15-15
Original file line numberDiff line numberDiff line change
@@ -672,31 +672,31 @@ Hi!
672672

673673
[^unused]: This is unused.
674674
.
675-
<p>This is some text!<sup class="footnote-ref"><a href="#fn-1" id="fnref-1">1</a></sup>. Other text.<sup class="footnote-ref"><a href="#fn-footnote" id="fnref-footnote">2</a></sup>.</p>
676-
<p>Here's a thing<sup class="footnote-ref"><a href="#fn-other-note" id="fnref-other-note">3</a></sup>.</p>
677-
<p>And another thing<sup class="footnote-ref"><a href="#fn-codeblock-note" id="fnref-codeblock-note">4</a></sup>.</p>
675+
<p>This is some text!<sup class="footnote-ref"><a href="#fn-1" id="fnref-1" data-footnote-ref>1</a></sup>. Other text.<sup class="footnote-ref"><a href="#fn-footnote" id="fnref-footnote" data-footnote-ref>2</a></sup>.</p>
676+
<p>Here's a thing<sup class="footnote-ref"><a href="#fn-other-note" id="fnref-other-note" data-footnote-ref>3</a></sup>.</p>
677+
<p>And another thing<sup class="footnote-ref"><a href="#fn-codeblock-note" id="fnref-codeblock-note" data-footnote-ref>4</a></sup>.</p>
678678
<p>This doesn't have a referent[^nope].</p>
679679
<p>Hi!</p>
680-
<section class="footnotes">
680+
<section class="footnotes" data-footnotes>
681681
<ol>
682682
<li id="fn-1">
683-
<p>Some <em>bolded</em> footnote definition. <a href="#fnref-1" class="footnote-backref">↩</a></p>
683+
<p>Some <em>bolded</em> footnote definition. <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
684684
</li>
685685
<li id="fn-footnote">
686686
<blockquote>
687687
<p>Blockquotes can be in a footnote.</p>
688688
</blockquote>
689689
<pre><code>as well as code blocks
690690
</code></pre>
691-
<p>or, naturally, simple paragraphs. <a href="#fnref-footnote" class="footnote-backref">↩</a></p>
691+
<p>or, naturally, simple paragraphs. <a href="#fnref-footnote" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
692692
</li>
693693
<li id="fn-other-note">
694-
<p>no code block here (spaces are stripped away) <a href="#fnref-other-note" class="footnote-backref">↩</a></p>
694+
<p>no code block here (spaces are stripped away) <a href="#fnref-other-note" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
695695
</li>
696696
<li id="fn-codeblock-note">
697697
<pre><code>this is now a code block (8 spaces indentation)
698698
</code></pre>
699-
<a href="#fnref-codeblock-note" class="footnote-backref">↩</a>
699+
<a href="#fnref-codeblock-note" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a>
700700
</li>
701701
</ol>
702702
</section>
@@ -711,12 +711,12 @@ This footnote is referenced[^a-footnote] multiple times, in lots of different pl
711711

712712
[^a-footnote]: This footnote definition should have three backrefs.
713713
.
714-
<p>This is some text. It has a footnote<sup class="footnote-ref"><a href="#fn-a-footnote" id="fnref-a-footnote">1</a></sup>.</p>
715-
<p>This footnote is referenced<sup class="footnote-ref"><a href="#fn-a-footnote" id="fnref-a-footnote-2">1</a></sup> multiple times, in lots of different places.<sup class="footnote-ref"><a href="#fn-a-footnote" id="fnref-a-footnote-3">1</a></sup></p>
716-
<section class="footnotes">
714+
<p>This is some text. It has a footnote<sup class="footnote-ref"><a href="#fn-a-footnote" id="fnref-a-footnote" data-footnote-ref>1</a></sup>.</p>
715+
<p>This footnote is referenced<sup class="footnote-ref"><a href="#fn-a-footnote" id="fnref-a-footnote-2" data-footnote-ref>1</a></sup> multiple times, in lots of different places.<sup class="footnote-ref"><a href="#fn-a-footnote" id="fnref-a-footnote-3" data-footnote-ref>1</a></sup></p>
716+
<section class="footnotes" data-footnotes>
717717
<ol>
718718
<li id="fn-a-footnote">
719-
<p>This footnote definition should have three backrefs. <a href="#fnref-a-footnote" class="footnote-backref">↩</a> <a href="#fnref-a-footnote-2" class="footnote-backref">↩<sup class="footnote-ref">2</sup></a> <a href="#fnref-a-footnote-3" class="footnote-backref">↩<sup class="footnote-ref">3</sup></a></p>
719+
<p>This footnote definition should have three backrefs. <a href="#fnref-a-footnote" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a> <a href="#fnref-a-footnote-2" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩<sup class="footnote-ref">2</sup></a> <a href="#fnref-a-footnote-3" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩<sup class="footnote-ref">3</sup></a></p>
720720
</li>
721721
</ol>
722722
</section>
@@ -729,11 +729,11 @@ Hello[^"><script>alert(1)</script>]
729729

730730
[^"><script>alert(1)</script>]: pwned
731731
.
732-
<p>Hello<sup class="footnote-ref"><a href="#fn-%22%3E%3Cscript%3Ealert(1)%3C/script%3E" id="fnref-%22%3E%3Cscript%3Ealert(1)%3C/script%3E">1</a></sup></p>
733-
<section class="footnotes">
732+
<p>Hello<sup class="footnote-ref"><a href="#fn-%22%3E%3Cscript%3Ealert(1)%3C/script%3E" id="fnref-%22%3E%3Cscript%3Ealert(1)%3C/script%3E" data-footnote-ref>1</a></sup></p>
733+
<section class="footnotes" data-footnotes>
734734
<ol>
735735
<li id="fn-%22%3E%3Cscript%3Ealert(1)%3C/script%3E">
736-
<p>pwned <a href="#fnref-%22%3E%3Cscript%3Ealert(1)%3C/script%3E" class="footnote-backref">↩</a></p>
736+
<p>pwned <a href="#fnref-%22%3E%3Cscript%3Ealert(1)%3C/script%3E" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
737737
</li>
738738
</ol>
739739
</section>

test/regression.txt

+19-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Issue #113: EOL character weirdness on Windows
44
(Important: first line ends with CR + CR + LF)
55

66
```````````````````````````````` example
7-
line1
7+
line1
8+
89
line2
910
.
1011
<p>line1</p>
@@ -175,7 +176,7 @@ A footnote in a paragraph[^1]
175176

176177
[^1]: a footnote
177178
.
178-
<p>A footnote in a paragraph<sup class="footnote-ref"><a href="#fn-1" id="fnref-1">1</a></sup></p>
179+
<p>A footnote in a paragraph<sup class="footnote-ref"><a href="#fn-1" id="fnref-1" data-footnote-ref>1</a></sup></p>
179180
<table>
180181
<thead>
181182
<tr>
@@ -185,15 +186,15 @@ A footnote in a paragraph[^1]
185186
</thead>
186187
<tbody>
187188
<tr>
188-
<td>foot <sup class="footnote-ref"><a href="#fn-1" id="fnref-1-2">1</a></sup></td>
189+
<td>foot <sup class="footnote-ref"><a href="#fn-1" id="fnref-1-2" data-footnote-ref>1</a></sup></td>
189190
<td>note</td>
190191
</tr>
191192
</tbody>
192193
</table>
193-
<section class="footnotes">
194+
<section class="footnotes" data-footnotes>
194195
<ol>
195196
<li id="fn-1">
196-
<p>a footnote <a href="#fnref-1" class="footnote-backref">↩</a> <a href="#fnref-1-2" class="footnote-backref">↩<sup class="footnote-ref">2</sup></a></p>
197+
<p>a footnote <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a> <a href="#fnref-1-2" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩<sup class="footnote-ref">2</sup></a></p>
197198
</li>
198199
</ol>
199200
</section>
@@ -279,14 +280,14 @@ This is some text. It has a citation.[^citation]
279280

280281
[^citation]: This is a long winded parapgraph that also has another citation.[^another-citation]
281282
.
282-
<p>This is some text. It has a citation.<sup class="footnote-ref"><a href="#fn-citation" id="fnref-citation">1</a></sup></p>
283-
<section class="footnotes">
283+
<p>This is some text. It has a citation.<sup class="footnote-ref"><a href="#fn-citation" id="fnref-citation" data-footnote-ref>1</a></sup></p>
284+
<section class="footnotes" data-footnotes>
284285
<ol>
285286
<li id="fn-citation">
286-
<p>This is a long winded parapgraph that also has another citation.<sup class="footnote-ref"><a href="#fn-another-citation" id="fnref-another-citation">2</a></sup> <a href="#fnref-citation" class="footnote-backref">↩</a></p>
287+
<p>This is a long winded parapgraph that also has another citation.<sup class="footnote-ref"><a href="#fn-another-citation" id="fnref-another-citation" data-footnote-ref>2</a></sup> <a href="#fnref-citation" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
287288
</li>
288289
<li id="fn-another-citation">
289-
<p>My second citation. <a href="#fnref-another-citation" class="footnote-backref">↩</a></p>
290+
<p>My second citation. <a href="#fnref-another-citation" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
290291
</li>
291292
</ol>
292293
</section>
@@ -301,14 +302,14 @@ This is some text. It has two footnotes references, side-by-side without any spa
301302

302303
[^footnote2]: Goodbye.
303304
.
304-
<p>This is some text. It has two footnotes references, side-by-side without any spaces,<sup class="footnote-ref"><a href="#fn-footnote1" id="fnref-footnote1">1</a></sup><sup class="footnote-ref"><a href="#fn-footnote2" id="fnref-footnote2">2</a></sup> which are definitely not link references.</p>
305-
<section class="footnotes">
305+
<p>This is some text. It has two footnotes references, side-by-side without any spaces,<sup class="footnote-ref"><a href="#fn-footnote1" id="fnref-footnote1" data-footnote-ref>1</a></sup><sup class="footnote-ref"><a href="#fn-footnote2" id="fnref-footnote2" data-footnote-ref>2</a></sup> which are definitely not link references.</p>
306+
<section class="footnotes" data-footnotes>
306307
<ol>
307308
<li id="fn-footnote1">
308-
<p>Hello. <a href="#fnref-footnote1" class="footnote-backref">↩</a></p>
309+
<p>Hello. <a href="#fnref-footnote1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
309310
</li>
310311
<li id="fn-footnote2">
311-
<p>Goodbye. <a href="#fnref-footnote2" class="footnote-backref">↩</a></p>
312+
<p>Goodbye. <a href="#fnref-footnote2" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
312313
</li>
313314
</ol>
314315
</section>
@@ -325,15 +326,15 @@ It has another footnote that contains many different characters (the autolinker
325326

326327
[^widely-cited]: this renders properly.
327328
.
328-
<p>This is some text. Sometimes the autolinker splits up text into multiple nodes, hoping it will find a hyperlink, so this text has a footnote whose reference label begins with a <code>w</code>.<sup class="footnote-ref"><a href="#fn-widely-cited" id="fnref-widely-cited">1</a></sup></p>
329-
<p>It has another footnote that contains many different characters (the autolinker was also breaking on <code>_</code>).<sup class="footnote-ref"><a href="#fn-sphinx-of-black-quartz_judge-my-vow-0123456789" id="fnref-sphinx-of-black-quartz_judge-my-vow-0123456789">2</a></sup></p>
330-
<section class="footnotes">
329+
<p>This is some text. Sometimes the autolinker splits up text into multiple nodes, hoping it will find a hyperlink, so this text has a footnote whose reference label begins with a <code>w</code>.<sup class="footnote-ref"><a href="#fn-widely-cited" id="fnref-widely-cited" data-footnote-ref>1</a></sup></p>
330+
<p>It has another footnote that contains many different characters (the autolinker was also breaking on <code>_</code>).<sup class="footnote-ref"><a href="#fn-sphinx-of-black-quartz_judge-my-vow-0123456789" id="fnref-sphinx-of-black-quartz_judge-my-vow-0123456789" data-footnote-ref>2</a></sup></p>
331+
<section class="footnotes" data-footnotes>
331332
<ol>
332333
<li id="fn-widely-cited">
333-
<p>this renders properly. <a href="#fnref-widely-cited" class="footnote-backref">↩</a></p>
334+
<p>this renders properly. <a href="#fnref-widely-cited" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
334335
</li>
335336
<li id="fn-sphinx-of-black-quartz_judge-my-vow-0123456789">
336-
<p>so does this. <a href="#fnref-sphinx-of-black-quartz_judge-my-vow-0123456789" class="footnote-backref">↩</a></p>
337+
<p>so does this. <a href="#fnref-sphinx-of-black-quartz_judge-my-vow-0123456789" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p>
337338
</li>
338339
</ol>
339340
</section>

0 commit comments

Comments
 (0)