Sha256: bee3f265536f74b363cd18efac8ff2175fb22ac08104559695c56c586fb44d6d

Contents?: true

Size: 1.33 KB

Versions: 11

Compression:

Stored size: 1.33 KB

Contents

description 'XML support'
require 'nokogiri'

# Nokogiri uses dump_html instead of serialize for broken libxml versions
# Unfortunately this breaks some things here.
# FIXME: Remove this check as soon as nokogiri works correctly.
raise 'The libxml version used by nokogiri is broken, upgrade to 2.7' if Nokogiri.uses_libxml? && %w[2 6] === Nokogiri::LIBXML_VERSION.split('.')[0..1]

class Nokogiri::XML::Node
  OLELO_DEFAULT_XHTML = SaveOptions::FORMAT |
    SaveOptions::NO_DECLARATION |
    SaveOptions::NO_EMPTY_TAGS |
    SaveOptions::AS_XML

  # HACK: Issue https://github.com/sparklemotion/nokogiri/issues/339
  def to_xhtml options = {}
    options[:save_with] |= OLELO_DEFAULT_XHTML if options[:save_with]
    options[:save_with] = OLELO_DEFAULT_XHTML unless options[:save_with]
    serialize(options)
  end
end

module XML
  extend self

  # Parse xml document string and return DOM object (Nokogiri)
  #
  # @param [String] xml document string
  # @return [Nokogiri::HTML::Document] Nokogiri Document
  def Document(xml)
    Nokogiri::HTML(xml, nil, 'UTF-8')
  end

  # Parse xml fragment and return DOM object (Nokogiri)
  #
  # @param [String] xml fragment string
  # @return [Nokogiri::HTML::DocumentFragment] Nokogiri Document Fragment
  def Fragment(xml)
    Nokogiri::HTML::DocumentFragment.new(Document(nil), xml)
  end
end

Olelo::XML = XML

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
olelo-0.9.15 plugins/utils/xml.rb
olelo-0.9.14 plugins/utils/xml.rb
olelo-0.9.13 plugins/utils/xml.rb
olelo-0.9.12 plugins/utils/xml.rb
olelo-0.9.11 plugins/utils/xml.rb
olelo-0.9.10 plugins/utils/xml.rb
olelo-0.9.9 plugins/utils/xml.rb
olelo-0.9.8 plugins/utils/xml.rb
olelo-0.9.7 plugins/utils/xml.rb
olelo-0.9.6 plugins/utils/xml.rb
olelo-0.9.5 plugins/utils/xml.rb