@@ -59,16 +59,30 @@ static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size
59
59
cmark_strbuf_put (html , data , (bufsize_t )len );
60
60
}
61
61
62
- static bool S_put_footnote_backref (cmark_html_renderer * renderer , cmark_strbuf * html ) {
62
+ static bool S_put_footnote_backref (cmark_html_renderer * renderer , cmark_strbuf * html , cmark_node * node ) {
63
63
if (renderer -> written_footnote_ix >= renderer -> footnote_ix )
64
64
return false;
65
65
renderer -> written_footnote_ix = renderer -> footnote_ix ;
66
66
67
- cmark_strbuf_puts (html , "<a href=\"#fnref" );
68
- char n [32 ];
69
- snprintf (n , sizeof (n ), "%d" , renderer -> footnote_ix );
70
- cmark_strbuf_puts (html , n );
71
- cmark_strbuf_puts (html , "\" class=\"footnote-backref\">↩</a>" );
67
+ cmark_strbuf_puts (html , "<a href=\"#fnref-" );
68
+ houdini_escape_href (html , node -> as .literal .data , node -> as .literal .len );
69
+ cmark_strbuf_puts (html , "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a>" );
70
+
71
+ if (node -> footnote .def_count > 1 )
72
+ {
73
+ for (int i = 2 ; i <= node -> footnote .def_count ; i ++ ) {
74
+ char n [32 ];
75
+ snprintf (n , sizeof (n ), "%d" , i );
76
+
77
+ cmark_strbuf_puts (html , " <a href=\"#fnref-" );
78
+ houdini_escape_href (html , node -> as .literal .data , node -> as .literal .len );
79
+ cmark_strbuf_puts (html , "-" );
80
+ cmark_strbuf_puts (html , n );
81
+ cmark_strbuf_puts (html , "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩<sup class=\"footnote-ref\">" );
82
+ cmark_strbuf_puts (html , n );
83
+ cmark_strbuf_puts (html , "</sup></a>" );
84
+ }
85
+ }
72
86
73
87
return true;
74
88
}
@@ -273,7 +287,7 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
273
287
} else {
274
288
if (parent -> type == CMARK_NODE_FOOTNOTE_DEFINITION && node -> next == NULL ) {
275
289
cmark_strbuf_putc (html , ' ' );
276
- S_put_footnote_backref (renderer , html );
290
+ S_put_footnote_backref (renderer , html , parent );
277
291
}
278
292
cmark_strbuf_puts (html , "</p>\n" );
279
293
}
@@ -405,16 +419,15 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
405
419
case CMARK_NODE_FOOTNOTE_DEFINITION :
406
420
if (entering ) {
407
421
if (renderer -> footnote_ix == 0 ) {
408
- cmark_strbuf_puts (html , "<section class=\"footnotes\">\n<ol>\n" );
422
+ cmark_strbuf_puts (html , "<section class=\"footnotes\" data-footnotes >\n<ol>\n" );
409
423
}
410
424
++ renderer -> footnote_ix ;
411
- cmark_strbuf_puts (html , "<li id=\"fn" );
412
- char n [32 ];
413
- snprintf (n , sizeof (n ), "%d" , renderer -> footnote_ix );
414
- cmark_strbuf_puts (html , n );
425
+
426
+ cmark_strbuf_puts (html , "<li id=\"fn-" );
427
+ houdini_escape_href (html , node -> as .literal .data , node -> as .literal .len );
415
428
cmark_strbuf_puts (html , "\">\n" );
416
429
} else {
417
- if (S_put_footnote_backref (renderer , html )) {
430
+ if (S_put_footnote_backref (renderer , html , node )) {
418
431
cmark_strbuf_putc (html , '\n' );
419
432
}
420
433
cmark_strbuf_puts (html , "</li>\n" );
@@ -423,12 +436,20 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
423
436
424
437
case CMARK_NODE_FOOTNOTE_REFERENCE :
425
438
if (entering ) {
426
- cmark_strbuf_puts (html , "<sup class=\"footnote-ref\"><a href=\"#fn" );
427
- cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
428
- cmark_strbuf_puts (html , "\" id=\"fnref" );
429
- cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
430
- cmark_strbuf_puts (html , "\">" );
431
- cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
439
+ cmark_strbuf_puts (html , "<sup class=\"footnote-ref\"><a href=\"#fn-" );
440
+ houdini_escape_href (html , node -> parent_footnote_def -> as .literal .data , node -> parent_footnote_def -> as .literal .len );
441
+ cmark_strbuf_puts (html , "\" id=\"fnref-" );
442
+ houdini_escape_href (html , node -> parent_footnote_def -> as .literal .data , node -> parent_footnote_def -> as .literal .len );
443
+
444
+ if (node -> footnote .ref_ix > 1 ) {
445
+ char n [32 ];
446
+ snprintf (n , sizeof (n ), "%d" , node -> footnote .ref_ix );
447
+ cmark_strbuf_puts (html , "-" );
448
+ cmark_strbuf_puts (html , n );
449
+ }
450
+
451
+ cmark_strbuf_puts (html , "\" data-footnote-ref>" );
452
+ houdini_escape_href (html , node -> as .literal .data , node -> as .literal .len );
432
453
cmark_strbuf_puts (html , "</a></sup>" );
433
454
}
434
455
break ;
0 commit comments