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

Save comments adjacent to the document element. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions gumbo_libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,23 @@ xmlDocPtr gumbo_libxml_parse_with_options(
BAD_CAST doctype->name,
BAD_CAST doctype->public_identifier,
BAD_CAST doctype->system_identifier);

xmlDocSetRootElement(doc, convert_node(doc, output->root, false));

GumboVector* children = &output->document->v.element.children;
for (unsigned int i = 0; i < children->length; i++) {
GumboNode* child = (GumboNode*) children->data[i];

switch (child->type) {
case GUMBO_NODE_COMMENT:
xmlAddChild((xmlNodePtr) doc, xmlNewDocComment(doc, BAD_CAST child->v.text.text));
break;
case GUMBO_NODE_ELEMENT:
xmlDocSetRootElement(doc, convert_node(doc, output->root, false));
break;
default:
break;
}
}

gumbo_destroy_output(options, output);
return doc;

Expand Down