lib/rdf/rdfa/reader/rexml.rb in rdf-rdfa-3.0.1 vs lib/rdf/rdfa/reader/rexml.rb in rdf-rdfa-3.1.0
- old
+ new
@@ -37,21 +37,23 @@
# @return [String]
def language
language = case
when @node.attribute("lang", RDF::XML.to_s)
@node.attribute("lang", RDF::XML.to_s)
+ when @node.attribute("xml:lang")
+ @node.attribute("xml:lang").to_s
when @node.attribute("lang")
@node.attribute("lang").to_s
end
end
##
# Return xml:base on element, if defined
#
# @return [String]
def base
- @node.attribute("base", RDF::XML.to_s)
+ @node.attribute("base", RDF::XML.to_s) || @node.attribute('xml:base')
end
def display_path
@display_path ||= begin
path = []
@@ -204,11 +206,11 @@
##
# Initializes the underlying XML library.
#
# @param [Hash{Symbol => Object}] options
# @return [void]
- def initialize_xml(input, options = {})
+ def initialize_xml(input, **options)
require 'rexml/document' unless defined?(::REXML)
@doc = case input
when ::REXML::Document
input
else
@@ -225,23 +227,21 @@
doc = ::REXML::Document.new(input.respond_to?(:read) ? input.read : input.to_s)
end
end
# Determine the host language and/or version from options and the input document
- def detect_host_language_version(input, options)
+ def detect_host_language_version(input, **options)
@host_language = options[:host_language] ? options[:host_language].to_sym : nil
@version = options[:version] ? options[:version].to_sym : nil
return if @host_language && @version
# Snif version based on input
case input
when ::REXML::Document
doc_type_string = input.doctype.to_s
version_attr = input.root && input.root.attribute("version").to_s
root_element = input.root.name.downcase
- root_namespace = input.root.namespace.to_s
- root_attrs = input.root.attributes
content_type = "application/xhtml+html" # FIXME: what about other possible XML types?
else
content_type = input.content_type if input.respond_to?(:content_type)
# Determine from head of document
@@ -255,11 +255,11 @@
end
doc_type_string = head.match(%r(<!DOCTYPE[^>]*>)m).to_s
root = head.match(%r(<[^!\?>]*>)m).to_s
root_element = root.match(%r(^<(\S+)[ >])) ? $1 : ""
- version_attr = root.match(/version\s+=\s+(\S+)[\s">]/m) ? $1 : ""
+ version_attr = root.match(/version\s*=\s*"([^"]+)"/m) ? $1 : ""
head_element = head.match(%r(<head.*<\/head>)mi)
head_doc = ::REXML::Document.new(head_element.to_s)
# May determine content-type and/or charset from meta
# Easist way is to parse head into a document and iterate
@@ -329,10 +329,10 @@
case @host_language
when :xhtml1, :xhtml5, :html4, :html5
base_el = ::REXML::XPath.first(@doc, "/html/head/base") rescue nil
base = base.join(base_el.attribute("href").to_s.split("#").first) if base_el
else
- xml_base = root.attribute("base", RDF::XML.to_s) if root
+ xml_base = root.attribute("base", RDF::XML.to_s) || root.attribute('xml:base') if root
base = base.join(xml_base) if xml_base
end
base || @base_uri
end