Skip to content

Commit

Permalink
Merge vmg#141 of the original project
Browse files Browse the repository at this point in the history
  • Loading branch information
dokutoku committed Mar 12, 2023
2 parents 164cc56 + 3b65796 commit 3e35e41
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 3 deletions.
53 changes: 53 additions & 0 deletions html/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,53 @@ rndr_finalize(struct buf *ob, void *opaque)
}
}

static void
rndr_footnotes(struct buf *ob, const struct buf *text, void *opaque)
{
BUFPUTSL(ob, "<div class=\"footnotes\">\n<hr />\n<ol>\n");

if (text)
bufput(ob, text->data, text->size);

BUFPUTSL(ob, "\n</ol>\n</div>\n");
}

static void
rndr_footnote_def(struct buf *ob, const struct buf *text, unsigned int num, void *opaque)
{
size_t i = 0;
int pfound = 0;

/* insert anchor at the end of first paragraph block */
if (text) {
while ((i+3) < text->size) {
if (text->data[i++] != '<') continue;
if (text->data[i++] != '/') continue;
if (text->data[i++] != 'p' && text->data[i] != 'P') continue;
if (text->data[i] != '>') continue;
i -= 3;
pfound = 1;
break;
}
}

bufprintf(ob, "\n<li id=\"fn%d\">\n", num);
if (pfound) {
bufput(ob, text->data, i);
bufprintf(ob, "&nbsp;<a href=\"#fnref%d\" rev=\"footnote\">&#8617;</a>", num);
bufput(ob, text->data + i, text->size - i);
} else if (text) {
bufput(ob, text->data, text->size);
}
BUFPUTSL(ob, "</li>\n");
}

static int
rndr_footnote_ref(struct buf *ob, unsigned int num, void *opaque)
{
bufprintf(ob, "<sup id=\"fnref%d\"><a href=\"#fn%d\" rel=\"footnote\">%d</a></sup>", num, num, num);
return 1;
}

static void
toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
Expand Down Expand Up @@ -594,6 +641,8 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio
NULL,
NULL,
NULL,
NULL,
NULL,

NULL,
rndr_codespan,
Expand All @@ -607,6 +656,7 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio
rndr_ins,
rndr_strikethrough,
rndr_superscript,
NULL,

NULL,
NULL,
Expand Down Expand Up @@ -638,6 +688,8 @@ sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options,
rndr_table,
rndr_tablerow,
rndr_tablecell,
rndr_footnotes,
rndr_footnote_def,

rndr_autolink,
rndr_codespan,
Expand All @@ -651,6 +703,7 @@ sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options,
rndr_ins,
rndr_strikethrough,
rndr_superscript,
rndr_footnote_ref,

NULL,
rndr_normal_text,
Expand Down
Loading

0 comments on commit 3e35e41

Please sign in to comment.