Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions html/html.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,54 @@ rndr_normal_text(struct buf *ob, const struct buf *text, void *opaque)
escape_html(ob, text->data, text->size);
}

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 @@ -554,6 +602,8 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio
NULL,
NULL,
NULL,
NULL,
NULL,

NULL,
rndr_codespan,
Expand All @@ -566,6 +616,7 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio
rndr_triple_emphasis,
rndr_strikethrough,
rndr_superscript,
NULL,

NULL,
NULL,
Expand Down Expand Up @@ -595,6 +646,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 @@ -607,6 +660,7 @@ sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options,
rndr_triple_emphasis,
rndr_strikethrough,
rndr_superscript,
rndr_footnote_ref,

NULL,
rndr_normal_text,
Expand Down
Loading