summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2017-08-01 19:28:16 +0700
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-07-07 19:30:34 +0200
commit55afc6fd496de4e75c27d725c2bf1470cc3cf5aa (patch)
tree9b28765be135f080a680bca08b33c017013af1b9 /src
parent26f5144fa925d5d7275819ff86388a47e6063f7e (diff)
Add xml:space="preserve" in XML output when appropriate
With current HTML escaping, sometimes we may produce an XML tag like <code_block> </code_block> Many XML parsers consider these spaces insignificant and strip them out but we need this. There's actually a test case like this in spec.txt (search "A code block can have all empty lines as its content:") and without proper hinting, an external xml->html converter will fail the spec. XML standard covers this case. If xml:space is "preserve", then whitespaces are significant and should be kept. Add this hint for text, code, code_block, html_inline and html_block tags.
Diffstat (limited to 'src')
-rw-r--r--src/xml.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/xml.c b/src/xml.c
index 4898cd2..48674cc 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -60,7 +60,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
case CMARK_NODE_CODE:
case CMARK_NODE_HTML_BLOCK:
case CMARK_NODE_HTML_INLINE:
- cmark_strbuf_puts(xml, ">");
+ cmark_strbuf_puts(xml, " xml:space=\"preserve\">");
escape_xml(xml, node->as.literal.data, node->as.literal.len);
cmark_strbuf_puts(xml, "</");
cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
@@ -100,7 +100,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
escape_xml(xml, node->as.code.info.data, node->as.code.info.len);
cmark_strbuf_putc(xml, '"');
}
- cmark_strbuf_puts(xml, ">");
+ cmark_strbuf_puts(xml, " xml:space=\"preserve\">");
escape_xml(xml, node->as.code.literal.data, node->as.code.literal.len);
cmark_strbuf_puts(xml, "</");
cmark_strbuf_puts(xml, cmark_node_get_type_string(node));