Sha256: 661e98e0ea1721c0a9d5da65bca15a1881b846e3ce67c08ea83a32e19b2d53c2

Contents?: true

Size: 619 Bytes

Versions: 2

Compression:

Stored size: 619 Bytes

Contents

require 'friendly_format/adapter/abstract'
require 'libxml'

module FriendlyFormat
  class LibxmlAdapter
    extend Abstract

    def self.parse html
      parser = LibXML::XML::HTMLParser.string(
        "<zzz>#{html}</zzz>",
        :options => LibXML::XML::HTMLParser::Options::RECOVER)

      # root is html, children is [body], first is body
      # same as nokogiri
      # drop zzz with .children.first since it would wrap a tag p for the article
      parser.parse.root.children.first.children.first
    end

    def self.to_xhtml node
      node.to_s
    end

  end # of LibxmlAdapter
end # of FriendlyFormat

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
godfat-friendly_format-0.6.1 lib/friendly_format/adapter/libxml_adapter.rb
friendly_format-0.6.1 lib/friendly_format/adapter/libxml_adapter.rb