Skip to content

Commit

Permalink
XML: don't render interior document nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jan 18, 2024
1 parent 50c46fe commit eb1a857
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
bool entering = (ev_type == CMARK_EVENT_ENTER);
char buffer[BUFFER_SIZE];

if (entering) {
// Only the root no-op node gets rendered as an XML document note.
//
// Thus non-root (have parent) no-op nodes are not rendered, and every
// other type of node is rendered.
bool render_node = !(node->parent && node->type == CMARK_NODE_NO_OP);

if (render_node && entering) {
indent(state);
cmark_strbuf_putc(xml, '<');
cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
Expand Down Expand Up @@ -195,7 +201,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
}
cmark_strbuf_puts(xml, ">\n");

} else if (node->first_child) {
} else if (render_node && node->first_child) {
state->indent -= 2;
indent(state);
cmark_strbuf_puts(xml, "</");
Expand Down

0 comments on commit eb1a857

Please sign in to comment.