@@ -59,17 +59,31 @@ 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 );
67+ cmark_strbuf_puts (html , "<a href=\"#fnref:" );
68+ cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
7169 cmark_strbuf_puts (html , "\" class=\"footnote-backref\">↩</a>" );
7270
71+ if (node -> footnote .count > 1 )
72+ {
73+ for (int i = 2 ; i <= node -> footnote .count ; i ++ ) {
74+ char n [32 ];
75+ snprintf (n , sizeof (n ), "%d" , i );
76+
77+ cmark_strbuf_puts (html , " <a href=\"#fnref:" );
78+ cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
79+ cmark_strbuf_puts (html , ":" );
80+ cmark_strbuf_put (html , (const unsigned char * )n , strlen (n ));
81+ cmark_strbuf_puts (html , "\" class=\"footnote-backref\">↩<sup class=\"footnote-ref\">" );
82+ cmark_strbuf_put (html , (const unsigned char * )n , strlen (n ));
83+ cmark_strbuf_puts (html , "</sup></a>" );
84+ }
85+ }
86+
7387 return true;
7488}
7589
@@ -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 }
@@ -395,13 +409,12 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
395409 cmark_strbuf_puts (html , "<section class=\"footnotes\">\n<ol>\n" );
396410 }
397411 ++ renderer -> footnote_ix ;
398- cmark_strbuf_puts (html , "<li id=\"fn" );
399- char n [32 ];
400- snprintf (n , sizeof (n ), "%d" , renderer -> footnote_ix );
401- cmark_strbuf_puts (html , n );
412+
413+ cmark_strbuf_puts (html , "<li id=\"fn:" );
414+ cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
402415 cmark_strbuf_puts (html , "\">\n" );
403416 } else {
404- if (S_put_footnote_backref (renderer , html )) {
417+ if (S_put_footnote_backref (renderer , html , node )) {
405418 cmark_strbuf_putc (html , '\n' );
406419 }
407420 cmark_strbuf_puts (html , "</li>\n" );
@@ -410,10 +423,18 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
410423
411424 case CMARK_NODE_FOOTNOTE_REFERENCE :
412425 if (entering ) {
413- cmark_strbuf_puts (html , "<sup class=\"footnote-ref\"><a href=\"#fn" );
414- cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
415- cmark_strbuf_puts (html , "\" id=\"fnref" );
416- cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
426+ cmark_strbuf_puts (html , "<sup class=\"footnote-ref\"><a href=\"#fn:" );
427+ cmark_strbuf_puts (html , node -> user_data );
428+ cmark_strbuf_puts (html , "\" id=\"fnref:" );
429+ cmark_strbuf_puts (html , node -> user_data );
430+
431+ if (node -> footnote .ix > 1 ) {
432+ char n [32 ];
433+ snprintf (n , sizeof (n ), "%d" , node -> footnote .ix );
434+ cmark_strbuf_puts (html , ":" );
435+ cmark_strbuf_put (html , (const unsigned char * )n , strlen (n ));
436+ }
437+
417438 cmark_strbuf_puts (html , "\">" );
418439 cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
419440 cmark_strbuf_puts (html , "</a></sup>" );
0 commit comments