class Nokogumbo

Public Class Methods

parse(p1) click to toggle source
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");
#ifdef NGLIB
  doc->type = XML_HTML_DOCUMENT_NODE;
#endif
  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);
}