use of nokogiri.HtmlDocument in project nokogiri by sparklemotion.
the class HtmlDomParserContext method wrapDocument.
@Override
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klazz, Document document) {
HtmlDocument htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), klazz);
htmlDocument.setDocumentNode(context, document);
if (ruby_encoding.isNil()) {
// ruby_encoding might have detected by HtmlDocument::EncodingReader
if (detected_encoding != null && !detected_encoding.isNil()) {
ruby_encoding = detected_encoding;
} else {
// no encoding given & no encoding detected, then try to get it
String charset = tryGetCharsetFromHtml5MetaTag(document);
ruby_encoding = stringOrNil(context.getRuntime(), charset);
}
}
htmlDocument.setEncoding(ruby_encoding);
htmlDocument.setParsedEncoding(java_encoding);
return htmlDocument;
}
Aggregations