| 90 | } |
| 91 | |
| 92 | static int S_render_node(cmark_node *node, cmark_event_type ev_type, |
| 93 | struct render_state *state, int options) { |
| 94 | cmark_strbuf *xml = state->xml; |
| 95 | bool literal = false; |
| 96 | cmark_delim_type delim; |
| 97 | bool entering = (ev_type == CMARK_EVENT_ENTER); |
| 98 | char buffer[BUFFER_SIZE]; |
| 99 | |
| 100 | if (entering) { |
| 101 | indent(state); |
| 102 | cmark_strbuf_putc(xml, '<'); |
| 103 | cmark_strbuf_puts(xml, cmark_node_get_type_string(node)); |
| 104 | |
| 105 | if (options & CMARK_OPT_SOURCEPOS && node->start_line != 0) { |
| 106 | snprintf(buffer, BUFFER_SIZE, " sourcepos=\"%d:%d-%d:%d\"", |
| 107 | node->start_line, node->start_column, node->end_line, |
| 108 | node->end_column); |
| 109 | cmark_strbuf_puts(xml, buffer); |
| 110 | } |
| 111 | |
| 112 | literal = false; |
| 113 | |
| 114 | switch (node->type) { |
| 115 | case CMARK_NODE_DOCUMENT: |
| 116 | cmark_strbuf_puts(xml, " xmlns=\"http://commonmark.org/xml/1.0\""); |
| 117 | break; |
| 118 | case CMARK_NODE_TEXT: |
| 119 | case CMARK_NODE_CODE: |
| 120 | case CMARK_NODE_HTML_BLOCK: |
| 121 | case CMARK_NODE_HTML_INLINE: |
| 122 | cmark_strbuf_puts(xml, " xml:space=\"preserve\">"); |
| 123 | escape_xml(xml, node->data, node->len); |
| 124 | cmark_strbuf_puts(xml, "</"); |
| 125 | cmark_strbuf_puts(xml, cmark_node_get_type_string(node)); |
| 126 | literal = true; |
| 127 | break; |
| 128 | case CMARK_NODE_LIST: |
| 129 | switch (cmark_node_get_list_type(node)) { |
| 130 | case CMARK_ORDERED_LIST: |
| 131 | cmark_strbuf_puts(xml, " type=\"ordered\""); |
| 132 | snprintf(buffer, BUFFER_SIZE, " start=\"%d\"", |
| 133 | cmark_node_get_list_start(node)); |
| 134 | cmark_strbuf_puts(xml, buffer); |
| 135 | delim = cmark_node_get_list_delim(node); |
| 136 | if (delim == CMARK_PAREN_DELIM) { |
| 137 | cmark_strbuf_puts(xml, " delim=\"paren\""); |
| 138 | } else if (delim == CMARK_PERIOD_DELIM) { |
| 139 | cmark_strbuf_puts(xml, " delim=\"period\""); |
| 140 | } |
| 141 | break; |
| 142 | case CMARK_BULLET_LIST: |
| 143 | cmark_strbuf_puts(xml, " type=\"bullet\""); |
| 144 | break; |
| 145 | default: |
| 146 | break; |
| 147 | } |
| 148 | snprintf(buffer, BUFFER_SIZE, " tight=\"%s\"", |
| 149 | (cmark_node_get_list_tight(node) ? "true" : "false")); |
no test coverage detected