From 33dd71fe8e497943d6d062bb6a2c0db185b2a24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=96=D1=83=D0=BC?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D0=BD?= Date: Tue, 22 May 2018 13:02:37 +0300 Subject: [PATCH] fix serialization Make serialization by spec: "If current node is an area, base, basefont, bgsound, br, col, embed, frame, hr, img, input, link, meta, param, spacer, or wbr element, then continue on to the next child node at this point." https://html.spec.whatwg.org/multipage/parsing.html#serialising-html-fragments --- source/myhtml/serialization.c | 52 +++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/source/myhtml/serialization.c b/source/myhtml/serialization.c index c142c91..157d331 100755 --- a/source/myhtml/serialization.c +++ b/source/myhtml/serialization.c @@ -242,23 +242,47 @@ mystatus_t myhtml_serialization_attributes(myhtml_tree_t* tree, myhtml_tree_attr */ mystatus_t myhtml_serialization_node_append_close(myhtml_tree_node_t* node, mycore_callback_serialize_f callback, void* ptr) { - if(node->tag_id != MyHTML_TAG__TEXT && - node->tag_id != MyHTML_TAG__COMMENT && - node->tag_id != MyHTML_TAG__DOCTYPE) - { - size_t length; - const char *tag = myhtml_tag_name_by_id(node->tree, node->tag_id, &length); + switch (node->tag_id) { + case MyHTML_TAG__TEXT: + case MyHTML_TAG__COMMENT: + case MyHTML_TAG__DOCTYPE: + return MyCORE_STATUS_OK; - if(callback("", 1, ptr)) - return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION; + // https://html.spec.whatwg.org/multipage/parsing.html#serialising-html-fragments + case MyHTML_TAG_AREA: + case MyHTML_TAG_BASE: + case MyHTML_TAG_BGSOUND: + case MyHTML_TAG_BR: + case MyHTML_TAG_COL: + case MyHTML_TAG_EMBED: + case MyHTML_TAG_FRAME: + case MyHTML_TAG_HR: + case MyHTML_TAG_IMG: + case MyHTML_TAG_INPUT: + case MyHTML_TAG_KEYGEN: + case MyHTML_TAG_LINK: + case MyHTML_TAG_META: + case MyHTML_TAG_PARAM: + case MyHTML_TAG_SOURCE: + case MyHTML_TAG_TRACK: + case MyHTML_TAG_WBR: + if(node->ns == MyHTML_NAMESPACE_HTML) + return MyCORE_STATUS_OK; + break; } + size_t length; + const char *tag = myhtml_tag_name_by_id(node->tree, node->tag_id, &length); + + if(callback("", 1, ptr)) + return MyCORE_STATUS_ERROR_MEMORY_ALLOCATION; + return MyCORE_STATUS_OK; }