| 1 |
use super::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn footnotes() { |
| 5 |
html_opts!( |
| 6 |
[extension.footnotes], |
| 7 |
concat!( |
| 8 |
"Here is a[^nowhere] footnote reference,[^1] and another.[^longnote]\n", |
| 9 |
"\n", |
| 10 |
"This is another note.[^note] And footnote[^longnote] is referenced again.\n", |
| 11 |
"\n", |
| 12 |
"[^note]: Hi.\n", |
| 13 |
"\n", |
| 14 |
"[^1]: Here is the footnote.\n", |
| 15 |
"\n", |
| 16 |
"[^longnote]: Here's one with multiple blocks.\n", |
| 17 |
"\n", |
| 18 |
" Subsequent paragraphs are indented.\n", |
| 19 |
"\n", |
| 20 |
" code\n", |
| 21 |
"\n", |
| 22 |
"This is regular content.\n", |
| 23 |
"\n", |
| 24 |
"[^unused]: This is not used.\n" |
| 25 |
), |
| 26 |
concat!( |
| 27 |
"<p>Here is a[^nowhere] footnote reference,<sup class=\"footnote-ref\"><a href=\"#fn-1\" \ |
| 28 |
id=\"fnref-1\" data-footnote-ref>1</a></sup> and another.<sup class=\"footnote-ref\"><a \ |
| 29 |
href=\"#fn-longnote\" id=\"fnref-longnote\" data-footnote-ref>2</a></sup></p>\n", |
| 30 |
"<p>This is another note.<sup class=\"footnote-ref\"><a \ |
| 31 |
href=\"#fn-note\" id=\"fnref-note\" data-footnote-ref>3</a></sup> And footnote<sup class=\"footnote-ref\"><a \ |
| 32 |
href=\"#fn-longnote\" id=\"fnref-longnote-2\" data-footnote-ref>2</a></sup> is referenced again.</p>\n", |
| 33 |
"<p>This is regular content.</p>\n", |
| 34 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 35 |
"<ol>\n", |
| 36 |
"<li id=\"fn-1\">\n", |
| 37 |
"<p>Here is the footnote. <a href=\"#fnref-1\" \ |
| 38 |
class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n", |
| 39 |
"</li>\n", |
| 40 |
"<li id=\"fn-longnote\">\n", |
| 41 |
"<p>Here's one with multiple blocks.</p>\n", |
| 42 |
"<p>Subsequent paragraphs are indented.</p>\n", |
| 43 |
"<pre><code>code\n", |
| 44 |
"</code></pre>\n", |
| 45 |
"<a href=\"#fnref-longnote\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"2\" aria-label=\"Back to reference 2\">↩</a> \ |
| 46 |
<a href=\"#fnref-longnote-2\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"2-2\" aria-label=\"Back to reference 2-2\">↩<sup class=\"footnote-ref\">2</sup></a>\n", |
| 47 |
"</li>\n", |
| 48 |
"<li id=\"fn-note\">\n", |
| 49 |
"<p>Hi. <a href=\"#fnref-note\" \ |
| 50 |
class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"3\" aria-label=\"Back to reference 3\">↩</a></p>\n", |
| 51 |
"</li>\n", |
| 52 |
"</ol>\n", |
| 53 |
"</section>\n" |
| 54 |
), |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn footnote_does_not_eat_exclamation() { |
| 60 |
html_opts!( |
| 61 |
[extension.footnotes], |
| 62 |
concat!("Here's my footnote![^a]\n", "\n", "[^a]: Yep.\n"), |
| 63 |
concat!( |
| 64 |
"<p>Here's my footnote!<sup class=\"footnote-ref\"><a href=\"#fn-a\" id=\"fnref-a\" data-footnote-ref>1</a></sup></p>\n", |
| 65 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 66 |
"<ol>\n", |
| 67 |
"<li id=\"fn-a\">\n", |
| 68 |
"<p>Yep. <a href=\"#fnref-a\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n", |
| 69 |
"</li>\n", |
| 70 |
"</ol>\n", |
| 71 |
"</section>\n" |
| 72 |
), |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
#[test] |
| 77 |
fn footnote_in_table() { |
| 78 |
html_opts!( |
| 79 |
[extension.table, extension.footnotes], |
| 80 |
concat!( |
| 81 |
"A footnote in a paragraph[^1]\n", |
| 82 |
"\n", |
| 83 |
"| Column1 | Column2 |\n", |
| 84 |
"| --------- | ------- |\n", |
| 85 |
"| foot [^1] | note |\n", |
| 86 |
"\n", |
| 87 |
"[^1]: a footnote\n", |
| 88 |
), |
| 89 |
concat!( |
| 90 |
"<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", |
| 91 |
"<table>\n", |
| 92 |
"<thead>\n", |
| 93 |
"<tr>\n", |
| 94 |
"<th>Column1</th>\n", |
| 95 |
"<th>Column2</th>\n", |
| 96 |
"</tr>\n", |
| 97 |
"</thead>\n", |
| 98 |
"<tbody>\n", |
| 99 |
"<tr>\n", |
| 100 |
"<td>foot <sup class=\"footnote-ref\"><a href=\"#fn-1\" id=\"fnref-1-2\" data-footnote-ref>1</a></sup></td>\n", |
| 101 |
"<td>note</td>\n", |
| 102 |
"</tr>\n", |
| 103 |
"</tbody>\n", |
| 104 |
"</table>\n", |
| 105 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 106 |
"<ol>\n", |
| 107 |
"<li id=\"fn-1\">\n", |
| 108 |
"<p>a footnote <a href=\"#fnref-1\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a> <a href=\"#fnref-1-2\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1-2\" aria-label=\"Back to reference 1-2\">↩<sup class=\"footnote-ref\">2</sup></a></p>\n", |
| 109 |
"</li>\n", |
| 110 |
"</ol>\n", |
| 111 |
"</section>\n", |
| 112 |
) |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
#[test] |
| 117 |
fn footnote_with_superscript() { |
| 118 |
html_opts!( |
| 119 |
[extension.superscript, extension.footnotes], |
| 120 |
concat!( |
| 121 |
"Here is a footnote reference.[^1]\n", |
| 122 |
"\n", |
| 123 |
"Here is a longer footnote reference.[^ref]\n", |
| 124 |
"\n", |
| 125 |
"e = mc^2^.\n", |
| 126 |
"\n", |
| 127 |
"[^1]: Here is the footnote.\n", |
| 128 |
"[^ref]: Here is another footnote.\n", |
| 129 |
), |
| 130 |
concat!( |
| 131 |
"<p>Here is a footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn-1\" \ |
| 132 |
id=\"fnref-1\" data-footnote-ref>1</a></sup></p>\n", |
| 133 |
"<p>Here is a longer footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn-ref\" \ |
| 134 |
id=\"fnref-ref\" data-footnote-ref>2</a></sup></p>\n", |
| 135 |
"<p>e = mc<sup>2</sup>.</p>\n", |
| 136 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 137 |
"<ol>\n", |
| 138 |
"<li id=\"fn-1\">\n", |
| 139 |
"<p>Here is the footnote. <a href=\"#fnref-1\" \ |
| 140 |
class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n", |
| 141 |
"</li>\n", |
| 142 |
"<li id=\"fn-ref\">\n", |
| 143 |
"<p>Here is another footnote. <a href=\"#fnref-ref\" \ |
| 144 |
class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"2\" aria-label=\"Back to reference 2\">↩</a></p>\n", |
| 145 |
"</li>\n", |
| 146 |
"</ol>\n", |
| 147 |
"</section>\n" |
| 148 |
), |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
#[test] |
| 153 |
fn footnote_escapes_name() { |
| 154 |
html_opts!( |
| 155 |
[extension.footnotes], |
| 156 |
concat!( |
| 157 |
"Here is a footnote reference.[^😄ref]\n", |
| 158 |
"\n", |
| 159 |
"[^😄ref]: Here is the footnote.\n", |
| 160 |
), |
| 161 |
concat!( |
| 162 |
"<p>Here is a footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn-%F0%9F%98%84ref\" id=\"fnref-%F0%9F%98%84ref\" data-footnote-ref>1</a></sup></p>\n", |
| 163 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 164 |
"<ol>\n", |
| 165 |
"<li id=\"fn-%F0%9F%98%84ref\">\n", |
| 166 |
"<p>Here is the footnote. <a href=\"#fnref-%F0%9F%98%84ref\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n", |
| 167 |
"</li>\n", |
| 168 |
"</ol>\n", |
| 169 |
"</section>\n" |
| 170 |
), |
| 171 |
); |
| 172 |
} |
| 173 |
|
| 174 |
#[test] |
| 175 |
fn footnote_case_insensitive_and_case_preserving() { |
| 176 |
html_opts!( |
| 177 |
[extension.footnotes], |
| 178 |
concat!( |
| 179 |
"Here is a footnote reference.[^AB] and [^ab]\n", |
| 180 |
"\n", |
| 181 |
"[^aB]: Here is the footnote.\n", |
| 182 |
), |
| 183 |
concat!( |
| 184 |
"<p>Here is a footnote reference.<sup class=\"footnote-ref\"><a href=\"#fn-aB\" id=\"fnref-aB\" data-footnote-ref>1</a></sup> and <sup class=\"footnote-ref\"><a href=\"#fn-aB\" id=\"fnref-aB-2\" data-footnote-ref>1</a></sup></p>\n", |
| 185 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 186 |
"<ol>\n", |
| 187 |
"<li id=\"fn-aB\">\n", |
| 188 |
"<p>Here is the footnote. <a href=\"#fnref-aB\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a> <a href=\"#fnref-aB-2\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1-2\" aria-label=\"Back to reference 1-2\">↩<sup class=\"footnote-ref\">2</sup></a></p>\n", |
| 189 |
"</li>\n", |
| 190 |
"</ol>\n", |
| 191 |
"</section>\n" |
| 192 |
), |
| 193 |
); |
| 194 |
} |
| 195 |
|
| 196 |
#[test] |
| 197 |
fn footnote_name_parsed_into_multiple_nodes() { |
| 198 |
html_opts!( |
| 199 |
[extension.footnotes], |
| 200 |
concat!("Foo.[^_ab]\n", "\n", "[^_ab]: Here is the footnote.\n",), |
| 201 |
concat!( |
| 202 |
"<p>Foo.<sup class=\"footnote-ref\"><a href=\"#fn-_ab\" id=\"fnref-_ab\" data-footnote-ref>1</a></sup></p>\n", |
| 203 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 204 |
"<ol>\n", |
| 205 |
"<li id=\"fn-_ab\">\n", |
| 206 |
"<p>Here is the footnote. <a href=\"#fnref-_ab\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n", |
| 207 |
"</li>\n", |
| 208 |
"</ol>\n", |
| 209 |
"</section>\n" |
| 210 |
), |
| 211 |
); |
| 212 |
} |
| 213 |
|
| 214 |
#[test] |
| 215 |
fn footnote_invalid_with_missing_name() { |
| 216 |
html_opts!( |
| 217 |
[extension.footnotes], |
| 218 |
"Foo.[^]\n\n[^]: Here is the footnote.\n", |
| 219 |
"<p>Foo.[^]</p>\n<p>[^]: Here is the footnote.</p>\n" |
| 220 |
); |
| 221 |
} |
| 222 |
|
| 223 |
#[test] |
| 224 |
fn footnote_does_not_allow_spaces_in_name() { |
| 225 |
html_opts!( |
| 226 |
[extension.footnotes], |
| 227 |
"Foo.[^one two]\n\n[^one two]: Here is the footnote.\n", |
| 228 |
"<p>Foo.[^one two]</p>\n<p>[^one two]: Here is the footnote.</p>\n" |
| 229 |
); |
| 230 |
} |
| 231 |
|
| 232 |
#[test] |
| 233 |
fn footnote_does_not_expand_emphasis_in_name() { |
| 234 |
html_opts!( |
| 235 |
[extension.footnotes], |
| 236 |
"Foo[^**one**]\n[^**one**]: bar\n", |
| 237 |
concat!( |
| 238 |
"<p>Foo<sup class=\"footnote-ref\"><a href=\"#fn-**one**\" id=\"fnref-**one**\" data-footnote-ref>1</a></sup></p>\n", |
| 239 |
"<section class=\"footnotes\" data-footnotes>\n", |
| 240 |
"<ol>\n", |
| 241 |
"<li id=\"fn-**one**\">\n", |
| 242 |
"<p>bar <a href=\"#fnref-**one**\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"1\" aria-label=\"Back to reference 1\">↩</a></p>\n", |
| 243 |
"</li>\n", |
| 244 |
"</ol>\n", |
| 245 |
"</section>\n" |
| 246 |
), |
| 247 |
); |
| 248 |
} |
| 249 |
|
| 250 |
#[test] |
| 251 |
fn sourcepos() { |
| 252 |
assert_ast_match!( |
| 253 |
[extension.footnotes], |
| 254 |
"Here is a footnote reference.[^1]\n" |
| 255 |
"\n" |
| 256 |
"[^1]: Here is the footnote.\n" |
| 257 |
"\n" |
| 258 |
"Here is a longer footnote reference.[^ref]\n" |
| 259 |
"\n" |
| 260 |
"[^ref]: Here is another footnote.\n", |
| 261 |
(document (1:1-7:33) [ |
| 262 |
(paragraph (1:1-1:33) [ |
| 263 |
(text (1:1-1:29) "Here is a footnote reference.") |
| 264 |
(footnote_reference (1:30-1:33)) |
| 265 |
]) |
| 266 |
(paragraph (5:1-5:42) [ |
| 267 |
(text (5:1-5:36) "Here is a longer footnote reference.") |
| 268 |
(footnote_reference (5:37-5:42)) |
| 269 |
]) |
| 270 |
(footnote_definition (3:1-3:27) [ |
| 271 |
(paragraph (3:7-3:27) [ |
| 272 |
(text (3:7-3:27) "Here is the footnote.") |
| 273 |
]) |
| 274 |
]) |
| 275 |
(footnote_definition (7:1-7:33) [ |
| 276 |
(paragraph (7:9-7:33) [ |
| 277 |
(text (7:9-7:33) "Here is another footnote.") |
| 278 |
]) |
| 279 |
]) |
| 280 |
]) |
| 281 |
); |
| 282 |
} |
| 283 |
|
| 284 |
#[test] |
| 285 |
fn leave_footnote_definitions() { |
| 286 |
assert_ast_match!( |
| 287 |
[extension.footnotes, parse.leave_footnote_definitions], |
| 288 |
"Here is a footnote reference.[^1]\n" |
| 289 |
"\n" |
| 290 |
"[^1]: Here is the footnote.\n" |
| 291 |
"\n" |
| 292 |
"Here is a longer footnote reference.[^ref]\n" |
| 293 |
"\n" |
| 294 |
"[^ref]: Here is another footnote.\n", |
| 295 |
(document (1:1-7:33) [ |
| 296 |
(paragraph (1:1-1:33) [ |
| 297 |
(text (1:1-1:29) "Here is a footnote reference.") |
| 298 |
(footnote_reference (1:30-1:33)) |
| 299 |
]) |
| 300 |
(footnote_definition (3:1-3:27) [ |
| 301 |
(paragraph (3:7-3:27) [ |
| 302 |
(text (3:7-3:27) "Here is the footnote.") |
| 303 |
]) |
| 304 |
]) |
| 305 |
(paragraph (5:1-5:42) [ |
| 306 |
(text (5:1-5:36) "Here is a longer footnote reference.") |
| 307 |
(footnote_reference (5:37-5:42)) |
| 308 |
]) |
| 309 |
(footnote_definition (7:1-7:33) [ |
| 310 |
(paragraph (7:9-7:33) [ |
| 311 |
(text (7:9-7:33) "Here is another footnote.") |
| 312 |
]) |
| 313 |
]) |
| 314 |
]) |
| 315 |
); |
| 316 |
} |