Skip to content

Commit cb72f1b

Browse files
authored
Merge pull request #273 from digitalmoksha/add-footnote-attributes
Add footnote attributes that mirror cmark-gfm
2 parents aaaf12e + fd6ebe7 commit cb72f1b

File tree

4 files changed

+57
-42
lines changed

4 files changed

+57
-42
lines changed

.github/workflows/rust.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push, pull_request]
44

55

66
jobs:
7-
build_test_spec:
7+
build_test:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
@@ -20,7 +20,22 @@ jobs:
2020
run: rustup override set ${{ matrix.rust }}
2121
- name: Build and test
2222
run: env SPEC=false script/cibuild
23-
- name: Run spec tests
23+
build_spec:
24+
runs-on: ubuntu-latest
25+
needs: build_test
26+
strategy:
27+
matrix:
28+
rust:
29+
- nightly
30+
- beta
31+
- stable
32+
steps:
33+
- uses: actions/checkout@v1
34+
with:
35+
submodules: true
36+
- name: Obtain Rust
37+
run: rustup override set ${{ matrix.rust }}
38+
- name: Build and run spec tests
2439
run: env SPEC=true script/cibuild
2540
build_wasm:
2641
runs-on: ubuntu-latest

src/html.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,10 @@ impl<'o> HtmlFormatter<'o> {
814814
if entering {
815815
if self.footnote_ix == 0 {
816816
self.output
817-
.write_all(b"<section class=\"footnotes\">\n<ol>\n")?;
817+
.write_all(b"<section class=\"footnotes\" data-footnotes>\n<ol>\n")?;
818818
}
819819
self.footnote_ix += 1;
820-
writeln!(self.output, "<li id=\"fn{}\">", self.footnote_ix)?;
820+
writeln!(self.output, "<li id=\"fn-{}\">", self.footnote_ix)?;
821821
} else {
822822
if self.put_footnote_backref()? {
823823
self.output.write_all(b"\n")?;
@@ -830,7 +830,7 @@ impl<'o> HtmlFormatter<'o> {
830830
let r = str::from_utf8(r).unwrap();
831831
write!(
832832
self.output,
833-
"<sup class=\"footnote-ref\"><a href=\"#fn{}\" id=\"fnref{}\">{}</a></sup>",
833+
"<sup class=\"footnote-ref\"><a href=\"#fn-{}\" id=\"fnref-{}\" data-footnote-ref>{}</a></sup>",
834834
r, r, r
835835
)?;
836836
}
@@ -859,7 +859,7 @@ impl<'o> HtmlFormatter<'o> {
859859
self.written_footnote_ix = self.footnote_ix;
860860
write!(
861861
self.output,
862-
"<a href=\"#fnref{}\" class=\"footnote-backref\">↩</a>",
862+
"<a href=\"#fnref-{}\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a>",
863863
self.footnote_ix
864864
)?;
865865
Ok(true)

src/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub struct ComrakExtensionOptions {
244244
/// let mut options = ComrakOptions::default();
245245
/// options.extension.footnotes = true;
246246
/// assert_eq!(markdown_to_html("Hi[^x].\n\n[^x]: A greeting.\n", &options),
247-
/// "<p>Hi<sup class=\"footnote-ref\"><a href=\"#fn1\" id=\"fnref1\">1</a></sup>.</p>\n<section class=\"footnotes\">\n<ol>\n<li id=\"fn1\">\n<p>A greeting. <a href=\"#fnref1\" class=\"footnote-backref\">↩</a></p>\n</li>\n</ol>\n</section>\n");
247+
/// "<p>Hi<sup class=\"footnote-ref\"><a href=\"#fn-1\" id=\"fnref-1\" data-footnote-ref>1</a></sup>.</p>\n<section class=\"footnotes\" data-footnotes>\n<ol>\n<li id=\"fn-1\">\n<p>A greeting. <a href=\"#fnref-1\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n</li>\n</ol>\n</section>\n");
248248
/// ```
249249
pub footnotes: bool,
250250

src/tests.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -982,28 +982,28 @@ fn footnotes() {
982982
"[^unused]: This is not used.\n"
983983
),
984984
concat!(
985-
"<p>Here is a[^nowhere] footnote reference,<sup class=\"footnote-ref\"><a href=\"#fn1\" \
986-
id=\"fnref1\">1</a></sup> and another.<sup class=\"footnote-ref\"><a \
987-
href=\"#fn2\" id=\"fnref2\">2</a></sup></p>\n",
988-
"<p>This is another note.<sup class=\"footnote-ref\"><a href=\"#fn3\" \
989-
id=\"fnref3\">3</a></sup></p>\n",
985+
"<p>Here is a[^nowhere] footnote reference,<sup class=\"footnote-ref\"><a href=\"#fn-1\" \
986+
id=\"fnref-1\" data-footnote-ref>1</a></sup> and another.<sup class=\"footnote-ref\"><a \
987+
href=\"#fn-2\" id=\"fnref-2\" data-footnote-ref>2</a></sup></p>\n",
988+
"<p>This is another note.<sup class=\"footnote-ref\"><a href=\"#fn-3\" \
989+
id=\"fnref-3\" data-footnote-ref>3</a></sup></p>\n",
990990
"<p>This is regular content.</p>\n",
991-
"<section class=\"footnotes\">\n",
991+
"<section class=\"footnotes\" data-footnotes>\n",
992992
"<ol>\n",
993-
"<li id=\"fn1\">\n",
994-
"<p>Here is the footnote. <a href=\"#fnref1\" \
995-
class=\"footnote-backref\">↩</a></p>\n",
993+
"<li id=\"fn-1\">\n",
994+
"<p>Here is the footnote. <a href=\"#fnref-1\" \
995+
class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n",
996996
"</li>\n",
997-
"<li id=\"fn2\">\n",
997+
"<li id=\"fn-2\">\n",
998998
"<p>Here's one with multiple blocks.</p>\n",
999999
"<p>Subsequent paragraphs are indented.</p>\n",
10001000
"<pre><code>code\n",
10011001
"</code></pre>\n",
1002-
"<a href=\"#fnref2\" class=\"footnote-backref\">↩</a>\n",
1002+
"<a href=\"#fnref-2\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a>\n",
10031003
"</li>\n",
1004-
"<li id=\"fn3\">\n",
1005-
"<p>Hi. <a href=\"#fnref3\" \
1006-
class=\"footnote-backref\">↩</a></p>\n",
1004+
"<li id=\"fn-3\">\n",
1005+
"<p>Hi. <a href=\"#fnref-3\" \
1006+
class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n",
10071007
"</li>\n",
10081008
"</ol>\n",
10091009
"</section>\n"
@@ -1017,12 +1017,12 @@ fn footnote_does_not_eat_exclamation() {
10171017
[extension.footnotes],
10181018
concat!("Here's my footnote![^a]\n", "\n", "[^a]: Yep.\n"),
10191019
concat!(
1020-
"<p>Here's my footnote!<sup class=\"footnote-ref\"><a href=\"#fn1\" \
1021-
id=\"fnref1\">1</a></sup></p>\n",
1022-
"<section class=\"footnotes\">\n",
1020+
"<p>Here's my footnote!<sup class=\"footnote-ref\"><a href=\"#fn-1\" \
1021+
id=\"fnref-1\" data-footnote-ref>1</a></sup></p>\n",
1022+
"<section class=\"footnotes\" data-footnotes>\n",
10231023
"<ol>\n",
1024-
"<li id=\"fn1\">\n",
1025-
"<p>Yep. <a href=\"#fnref1\" class=\"footnote-backref\">↩</a></p>\n",
1024+
"<li id=\"fn-1\">\n",
1025+
"<p>Yep. <a href=\"#fnref-1\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n",
10261026
"</li>\n",
10271027
"</ol>\n",
10281028
"</section>\n"
@@ -1043,7 +1043,7 @@ fn footnote_in_table() {
10431043
"\n",
10441044
"[^1]: a footnote\n",
10451045
), concat!(
1046-
"<p>A footnote in a paragraph<sup class=\"footnote-ref\"><a href=\"#fn1\" id=\"fnref1\">1</a></sup></p>\n",
1046+
"<p>A footnote in a paragraph<sup class=\"footnote-ref\"><a href=\"#fn-1\" id=\"fnref-1\" data-footnote-ref>1</a></sup></p>\n",
10471047
"<table>\n",
10481048
"<thead>\n",
10491049
"<tr>\n",
@@ -1053,15 +1053,15 @@ fn footnote_in_table() {
10531053
"</thead>\n",
10541054
"<tbody>\n",
10551055
"<tr>\n",
1056-
"<td>foot <sup class=\"footnote-ref\"><a href=\"#fn1\" id=\"fnref1\">1</a></sup></td>\n",
1056+
"<td>foot <sup class=\"footnote-ref\"><a href=\"#fn-1\" id=\"fnref-1\" data-footnote-ref>1</a></sup></td>\n",
10571057
"<td>note</td>\n",
10581058
"</tr>\n",
10591059
"</tbody>\n",
10601060
"</table>\n",
1061-
"<section class=\"footnotes\">\n",
1061+
"<section class=\"footnotes\" data-footnotes>\n",
10621062
"<ol>\n",
1063-
"<li id=\"fn1\">\n",
1064-
"<p>a footnote <a href=\"#fnref1\" class=\"footnote-backref\">↩</a></p>\n",
1063+
"<li id=\"fn-1\">\n",
1064+
"<p>a footnote <a href=\"#fnref-1\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n",
10651065
"</li>\n",
10661066
"</ol>\n",
10671067
"</section>\n",
@@ -1083,20 +1083,20 @@ fn footnote_with_superscript() {
10831083
"[^ref]: Here is another footnote.\n",
10841084
),
10851085
concat!(
1086-
"<p>Here is a footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn1\" \
1087-
id=\"fnref1\">1</a></sup></p>\n",
1088-
"<p>Here is a longer footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn2\" \
1089-
id=\"fnref2\">2</a></sup></p>\n",
1086+
"<p>Here is a footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn-1\" \
1087+
id=\"fnref-1\" data-footnote-ref>1</a></sup></p>\n",
1088+
"<p>Here is a longer footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn-2\" \
1089+
id=\"fnref-2\" data-footnote-ref>2</a></sup></p>\n",
10901090
"<p>e = mc<sup>2</sup>.</p>\n",
1091-
"<section class=\"footnotes\">\n",
1091+
"<section class=\"footnotes\" data-footnotes>\n",
10921092
"<ol>\n",
1093-
"<li id=\"fn1\">\n",
1094-
"<p>Here is the footnote. <a href=\"#fnref1\" \
1095-
class=\"footnote-backref\">↩</a></p>\n",
1093+
"<li id=\"fn-1\">\n",
1094+
"<p>Here is the footnote. <a href=\"#fnref-1\" \
1095+
class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n",
10961096
"</li>\n",
1097-
"<li id=\"fn2\">\n",
1098-
"<p>Here is another footnote. <a href=\"#fnref2\" \
1099-
class=\"footnote-backref\">↩</a></p>\n",
1097+
"<li id=\"fn-2\">\n",
1098+
"<p>Here is another footnote. <a href=\"#fnref-2\" \
1099+
class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n",
11001100
"</li>\n",
11011101
"</ol>\n",
11021102
"</section>\n"

0 commit comments

Comments
 (0)