Track document types when parsing.
When parsing XML/HTML documents the corresponding document type (:html or :xml) is stored in Document#type.
This commit is contained in:
1 parent
bd322e8716
commit
6fc7e2e254
4 files changed
+32
-2
No files matched your search
@@ -12,11 +12,15 @@ module Oga
|
||||
# The XML declaration of the document.
|
||||
# @return [Oga::XML::XmlDeclaration]
|
||||
#
|
||||
# @!attribute [rw] type
|
||||
# The document type, either `:xml` or `:html`.
|
||||
# @return [Symbol]
|
||||
#
|
||||
class Document
|
||||
include Querying
|
||||
include Traversal
|
||||
|
||||
attr_accessor :doctype, :xml_declaration
|
||||
attr_accessor :doctype, :xml_declaration, :type
|
||||
|
||||
##
|
||||
# @param [Hash] options
|
||||
@@ -24,10 +28,12 @@ module Oga
|
||||
# @option options [Oga::XML::NodeSet] :children
|
||||
# @option options [Oga::XML::Doctype] :doctype
|
||||
# @option options [Oga::XML::XmlDeclaration] :xml_declaration
|
||||
# @option options [Symbol] :type
|
||||
#
|
||||
def initialize(options = {})
|
||||
@doctype = options[:doctype]
|
||||
@xml_declaration = options[:xml_declaration]
|
||||
@type = options[:type] || :xml
|
||||
|
||||
self.children = options[:children] if options[:children]
|
||||
end
|
||||
|
||||
@@ -296,7 +296,9 @@ Unexpected #{name} with value #{value.inspect} on line #{@line}:
|
||||
# @return [Oga::XML::Document]
|
||||
#
|
||||
def on_document(children = [])
|
||||
document = Document.new
|
||||
document = Document.new(
|
||||
:type => @lexer.html ? :html : :xml
|
||||
)
|
||||
|
||||
children.each do |child|
|
||||
if child.is_a?(Doctype)
|
||||
|
||||
Reference in new issue
Block a user