@@ -59,16 +59,30 @@ static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size
5959 cmark_strbuf_put (html , data , (bufsize_t )len );
6060}
6161
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 ) {
6363 if (renderer -> written_footnote_ix >= renderer -> footnote_ix )
6464 return false;
6565 renderer -> written_footnote_ix = renderer -> footnote_ix ;
6666
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+ }
7286
7387 return true;
7488}
@@ -273,7 +287,7 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
273287 } else {
274288 if (parent -> type == CMARK_NODE_FOOTNOTE_DEFINITION && node -> next == NULL ) {
275289 cmark_strbuf_putc (html , ' ' );
276- S_put_footnote_backref (renderer , html );
290+ S_put_footnote_backref (renderer , html , parent );
277291 }
278292 cmark_strbuf_puts (html , "</p>\n" );
279293 }
@@ -405,16 +419,15 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
405419 case CMARK_NODE_FOOTNOTE_DEFINITION :
406420 if (entering ) {
407421 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" );
409423 }
410424 ++ 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 );
415428 cmark_strbuf_puts (html , "\">\n" );
416429 } else {
417- if (S_put_footnote_backref (renderer , html )) {
430+ if (S_put_footnote_backref (renderer , html , node )) {
418431 cmark_strbuf_putc (html , '\n' );
419432 }
420433 cmark_strbuf_puts (html , "</li>\n" );
@@ -423,12 +436,20 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
423436
424437 case CMARK_NODE_FOOTNOTE_REFERENCE :
425438 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 );
432453 cmark_strbuf_puts (html , "</a></sup>" );
433454 }
434455 break ;
0 commit comments