@@ -59,17 +59,31 @@ 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 );
67
+ cmark_strbuf_puts (html , "<a href=\"#fnref:" );
68
+ cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
71
69
cmark_strbuf_puts (html , "\" class=\"footnote-backref\">↩</a>" );
72
70
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
+
73
87
return true;
74
88
}
75
89
@@ -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
}
@@ -395,13 +409,12 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
395
409
cmark_strbuf_puts (html , "<section class=\"footnotes\">\n<ol>\n" );
396
410
}
397
411
++ 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 );
402
415
cmark_strbuf_puts (html , "\">\n" );
403
416
} else {
404
- if (S_put_footnote_backref (renderer , html )) {
417
+ if (S_put_footnote_backref (renderer , html , node )) {
405
418
cmark_strbuf_putc (html , '\n' );
406
419
}
407
420
cmark_strbuf_puts (html , "</li>\n" );
@@ -410,10 +423,18 @@ static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
410
423
411
424
case CMARK_NODE_FOOTNOTE_REFERENCE :
412
425
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
+
417
438
cmark_strbuf_puts (html , "\">" );
418
439
cmark_strbuf_put (html , node -> as .literal .data , node -> as .literal .len );
419
440
cmark_strbuf_puts (html , "</a></sup>" );
0 commit comments