Search in sources :

Example 6 with HtmlDocument

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;
}
Also used : HtmlDocument(nokogiri.HtmlDocument)

Aggregations

HtmlDocument (nokogiri.HtmlDocument)6 RubyString (org.jruby.RubyString)4 XmlAttr (nokogiri.XmlAttr)2 XmlDocument (nokogiri.XmlDocument)2 XmlNamespace (nokogiri.XmlNamespace)2 XmlNode (nokogiri.XmlNode)2 Attr (org.w3c.dom.Attr)2 Charset (java.nio.charset.Charset)1