Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML: add NODE_FOOTNOTE type strings and footnote emitters #362

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ const char *cmark_node_get_type_string(cmark_node *node) {
return "link";
case CMARK_NODE_IMAGE:
return "image";
case CMARK_NODE_FOOTNOTE_REFERENCE:
return "fnref";
case CMARK_NODE_FOOTNOTE_DEFINITION:
return "fn";
}

return "<unknown>";
Expand Down
19 changes: 19 additions & 0 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
escape_xml(xml, node->as.link.title.data, node->as.link.title.len);
cmark_strbuf_putc(xml, '"');
break;
case CMARK_NODE_FOOTNOTE_DEFINITION:
cmark_strbuf_puts(xml, " id=\"fn-");
escape_xml(xml, node->as.literal.data, node->as.literal.len);
cmark_strbuf_putc(xml, '"');
break;
case CMARK_NODE_FOOTNOTE_REFERENCE:
cmark_strbuf_puts(xml, " id=\"fnref-");
escape_xml(xml, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len);
if (node->footnote.ref_ix > 1) {
char n[32];
snprintf(n, sizeof(n), "%d", node->footnote.ref_ix);
cmark_strbuf_puts(xml, "-");
cmark_strbuf_puts(xml, n);
}
cmark_strbuf_putc(xml, '"');
cmark_strbuf_puts(xml, " destination=\"fn-");
escape_xml(xml, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len);
cmark_strbuf_putc(xml, '"');
break;
default:
break;
}
Expand Down