Class: Nokogumbo
- Inherits:
-
Object
- Object
- Nokogumbo
- Defined in:
- ext/nokogumboc/nokogumbo.c
Class Method Summary collapse
-
.parse(string) ⇒ Object
Parse a string using gumbo_parse into a Nokogiri document.
Class Method Details
.parse(string) ⇒ Object
Parse a string using gumbo_parse into a Nokogiri document
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'ext/nokogumboc/nokogumbo.c', line 146
static VALUE parse(VALUE self, VALUE string) {
GumboOutput *output = gumbo_parse_with_options(
&kGumboDefaultOptions, RSTRING_PTR(string),
(size_t) RSTRING_LEN(string)
);
xmlDocPtr doc = xmlNewDoc(CONST_CAST "1.0");
xmlNodePtr root = walk_tree(doc, &output->root->v.element);
xmlDocSetRootElement(doc, root);
if (output->document->v.document.has_doctype) {
const char *public = output->document->v.document.public_identifier;
const char *system = output->document->v.document.system_identifier;
xmlCreateIntSubset(doc, CONST_CAST "html",
(strlen(public) ? CONST_CAST public : NIL),
(strlen(system) ? CONST_CAST system : NIL));
}
gumbo_destroy_output(&kGumboDefaultOptions, output);
return Nokogiri_wrap_xml_document(Document, doc);
}
|