nokogiri 1.13.6 → 1.16.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +43 -0
- data/LICENSE-DEPENDENCIES.md +830 -509
- data/LICENSE.md +1 -1
- data/README.md +21 -11
- data/dependencies.yml +34 -15
- data/ext/nokogiri/extconf.rb +167 -48
- data/ext/nokogiri/gumbo.c +21 -11
- data/ext/nokogiri/html4_document.c +3 -4
- data/ext/nokogiri/html4_element_description.c +20 -15
- data/ext/nokogiri/html4_entity_lookup.c +2 -2
- data/ext/nokogiri/html4_sax_parser_context.c +11 -22
- data/ext/nokogiri/html4_sax_push_parser.c +4 -4
- data/ext/nokogiri/nokogiri.c +84 -75
- data/ext/nokogiri/nokogiri.h +46 -16
- data/ext/nokogiri/test_global_handlers.c +2 -2
- data/ext/nokogiri/xml_attr.c +3 -3
- data/ext/nokogiri/xml_attribute_decl.c +5 -5
- data/ext/nokogiri/xml_cdata.c +31 -18
- data/ext/nokogiri/xml_comment.c +2 -2
- data/ext/nokogiri/xml_document.c +135 -38
- data/ext/nokogiri/xml_document_fragment.c +2 -2
- data/ext/nokogiri/xml_dtd.c +9 -9
- data/ext/nokogiri/xml_element_content.c +34 -31
- data/ext/nokogiri/xml_element_decl.c +10 -10
- data/ext/nokogiri/xml_encoding_handler.c +15 -7
- data/ext/nokogiri/xml_entity_decl.c +6 -6
- data/ext/nokogiri/xml_entity_reference.c +2 -2
- data/ext/nokogiri/xml_namespace.c +75 -14
- data/ext/nokogiri/xml_node.c +365 -87
- data/ext/nokogiri/xml_node_set.c +129 -111
- data/ext/nokogiri/xml_processing_instruction.c +2 -2
- data/ext/nokogiri/xml_reader.c +126 -64
- data/ext/nokogiri/xml_relax_ng.c +67 -82
- data/ext/nokogiri/xml_sax_parser.c +45 -20
- data/ext/nokogiri/xml_sax_parser_context.c +50 -30
- data/ext/nokogiri/xml_sax_push_parser.c +31 -12
- data/ext/nokogiri/xml_schema.c +95 -118
- data/ext/nokogiri/xml_syntax_error.c +4 -4
- data/ext/nokogiri/xml_text.c +27 -14
- data/ext/nokogiri/xml_xpath_context.c +213 -136
- data/ext/nokogiri/xslt_stylesheet.c +126 -67
- data/gumbo-parser/Makefile +28 -0
- data/gumbo-parser/src/attribute.h +1 -1
- data/gumbo-parser/src/error.c +10 -6
- data/gumbo-parser/src/error.h +1 -1
- data/gumbo-parser/src/foreign_attrs.c +15 -16
- data/gumbo-parser/src/foreign_attrs.gperf +1 -1
- data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
- data/gumbo-parser/src/parser.c +29 -10
- data/gumbo-parser/src/replacement.h +1 -1
- data/gumbo-parser/src/string_buffer.h +1 -1
- data/gumbo-parser/src/string_piece.c +1 -1
- data/gumbo-parser/src/svg_attrs.c +2 -2
- data/gumbo-parser/src/svg_tags.c +2 -2
- data/gumbo-parser/src/tag.c +2 -1
- data/gumbo-parser/src/tag_lookup.c +7 -7
- data/gumbo-parser/src/tag_lookup.gperf +1 -0
- data/gumbo-parser/src/tag_lookup.h +1 -1
- data/gumbo-parser/src/token_buffer.h +1 -1
- data/gumbo-parser/src/tokenizer.c +2 -1
- data/gumbo-parser/src/tokenizer.h +1 -1
- data/gumbo-parser/src/utf8.c +1 -1
- data/gumbo-parser/src/utf8.h +1 -1
- data/gumbo-parser/src/util.c +1 -3
- data/gumbo-parser/src/util.h +4 -0
- data/gumbo-parser/src/vector.h +1 -1
- data/lib/nokogiri/css/node.rb +2 -2
- data/lib/nokogiri/css/parser_extras.rb +1 -1
- data/lib/nokogiri/css/xpath_visitor.rb +8 -26
- data/lib/nokogiri/css.rb +6 -0
- data/lib/nokogiri/decorators/slop.rb +1 -1
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +4 -3
- data/lib/nokogiri/html4/document.rb +3 -122
- data/lib/nokogiri/html4/document_fragment.rb +1 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +1827 -365
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4.rb +1 -0
- data/lib/nokogiri/html5/document.rb +113 -36
- data/lib/nokogiri/html5/document_fragment.rb +10 -3
- data/lib/nokogiri/html5/node.rb +8 -5
- data/lib/nokogiri/html5.rb +74 -226
- data/lib/nokogiri/jruby/dependencies.rb +1 -19
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +16 -14
- data/lib/nokogiri/xml/attr.rb +49 -0
- data/lib/nokogiri/xml/attribute_decl.rb +4 -2
- data/lib/nokogiri/xml/builder.rb +1 -1
- data/lib/nokogiri/xml/document.rb +103 -56
- data/lib/nokogiri/xml/document_fragment.rb +50 -7
- data/lib/nokogiri/xml/element_content.rb +10 -2
- data/lib/nokogiri/xml/element_decl.rb +4 -2
- data/lib/nokogiri/xml/entity_decl.rb +4 -2
- data/lib/nokogiri/xml/namespace.rb +41 -0
- data/lib/nokogiri/xml/node/save_options.rb +14 -4
- data/lib/nokogiri/xml/node.rb +241 -70
- data/lib/nokogiri/xml/node_set.rb +90 -11
- data/lib/nokogiri/xml/parse_options.rb +129 -50
- data/lib/nokogiri/xml/pp/node.rb +28 -15
- data/lib/nokogiri/xml/processing_instruction.rb +2 -1
- data/lib/nokogiri/xml/reader.rb +16 -17
- data/lib/nokogiri/xml/sax/document.rb +1 -1
- data/lib/nokogiri/xml/sax/parser.rb +2 -3
- data/lib/nokogiri/xml/searchable.rb +21 -13
- data/lib/nokogiri/xml/syntax_error.rb +1 -1
- data/lib/nokogiri/xml.rb +1 -1
- data/lib/nokogiri/xslt/stylesheet.rb +29 -7
- data/lib/nokogiri/xslt.rb +75 -5
- data/lib/nokogiri.rb +15 -15
- data/lib/xsd/xmlparser/nokogiri.rb +4 -2
- data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
- data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
- data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
- data/ports/archives/libxml2-2.12.9.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
- metadata +21 -248
- data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
- data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -3040
- data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +0 -61
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +0 -3037
- data/ports/archives/libxml2-2.9.14.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module HTML4
|
5
|
+
# Libxml2's parser has poor support for encoding detection. First, it does not recognize the
|
6
|
+
# HTML5 style meta charset declaration. Secondly, even if it successfully detects an encoding
|
7
|
+
# hint, it does not re-decode or re-parse the preceding part which may be garbled.
|
8
|
+
#
|
9
|
+
# EncodingReader aims to perform advanced encoding detection beyond what Libxml2 does, and to
|
10
|
+
# emulate rewinding of a stream and make Libxml2 redo parsing from the start when an encoding
|
11
|
+
# hint is found.
|
12
|
+
|
13
|
+
# :nodoc: all
|
14
|
+
class EncodingReader
|
15
|
+
class EncodingFound < StandardError
|
16
|
+
attr_reader :found_encoding
|
17
|
+
|
18
|
+
def initialize(encoding)
|
19
|
+
@found_encoding = encoding
|
20
|
+
super(format("encoding found: %s", encoding))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class SAXHandler < Nokogiri::XML::SAX::Document
|
25
|
+
attr_reader :encoding
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@encoding = nil
|
29
|
+
super()
|
30
|
+
end
|
31
|
+
|
32
|
+
def start_element(name, attrs = [])
|
33
|
+
return unless name == "meta"
|
34
|
+
|
35
|
+
attr = Hash[attrs]
|
36
|
+
(charset = attr["charset"]) &&
|
37
|
+
(@encoding = charset)
|
38
|
+
(http_equiv = attr["http-equiv"]) &&
|
39
|
+
http_equiv.match(/\AContent-Type\z/i) &&
|
40
|
+
(content = attr["content"]) &&
|
41
|
+
(m = content.match(/;\s*charset\s*=\s*([\w-]+)/)) &&
|
42
|
+
(@encoding = m[1])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class JumpSAXHandler < SAXHandler
|
47
|
+
def initialize(jumptag)
|
48
|
+
@jumptag = jumptag
|
49
|
+
super()
|
50
|
+
end
|
51
|
+
|
52
|
+
def start_element(name, attrs = [])
|
53
|
+
super
|
54
|
+
throw(@jumptag, @encoding) if @encoding
|
55
|
+
throw(@jumptag, nil) if /\A(?:div|h1|img|p|br)\z/.match?(name)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.detect_encoding(chunk)
|
60
|
+
(m = chunk.match(/\A(<\?xml[ \t\r\n][^>]*>)/)) &&
|
61
|
+
(return Nokogiri.XML(m[1]).encoding)
|
62
|
+
|
63
|
+
if Nokogiri.jruby?
|
64
|
+
(m = chunk.match(/(<meta\s)(.*)(charset\s*=\s*([\w-]+))(.*)/i)) &&
|
65
|
+
(return m[4])
|
66
|
+
catch(:encoding_found) do
|
67
|
+
Nokogiri::HTML4::SAX::Parser.new(JumpSAXHandler.new(:encoding_found)).parse(chunk)
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
else
|
71
|
+
handler = SAXHandler.new
|
72
|
+
parser = Nokogiri::HTML4::SAX::PushParser.new(handler)
|
73
|
+
begin
|
74
|
+
parser << chunk
|
75
|
+
rescue
|
76
|
+
Nokogiri::SyntaxError
|
77
|
+
end
|
78
|
+
handler.encoding
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize(io)
|
83
|
+
@io = io
|
84
|
+
@firstchunk = nil
|
85
|
+
@encoding_found = nil
|
86
|
+
end
|
87
|
+
|
88
|
+
# This method is used by the C extension so that
|
89
|
+
# Nokogiri::HTML4::Document#read_io() does not leak memory when
|
90
|
+
# EncodingFound is raised.
|
91
|
+
attr_reader :encoding_found
|
92
|
+
|
93
|
+
def read(len)
|
94
|
+
# no support for a call without len
|
95
|
+
|
96
|
+
unless @firstchunk
|
97
|
+
(@firstchunk = @io.read(len)) || return
|
98
|
+
|
99
|
+
# This implementation expects that the first call from
|
100
|
+
# htmlReadIO() is made with a length long enough (~1KB) to
|
101
|
+
# achieve advanced encoding detection.
|
102
|
+
if (encoding = EncodingReader.detect_encoding(@firstchunk))
|
103
|
+
# The first chunk is stored for the next read in retry.
|
104
|
+
raise @encoding_found = EncodingFound.new(encoding)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
@encoding_found = nil
|
108
|
+
|
109
|
+
ret = @firstchunk.slice!(0, len)
|
110
|
+
if (len -= ret.length) > 0
|
111
|
+
(rest = @io.read(len)) && ret << (rest)
|
112
|
+
end
|
113
|
+
if ret.empty?
|
114
|
+
nil
|
115
|
+
else
|
116
|
+
ret
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/lib/nokogiri/html4.rb
CHANGED
@@ -39,6 +39,7 @@ end
|
|
39
39
|
require_relative "html4/entity_lookup"
|
40
40
|
require_relative "html4/document"
|
41
41
|
require_relative "html4/document_fragment"
|
42
|
+
require_relative "html4/encoding_reader"
|
42
43
|
require_relative "html4/sax/parser_context"
|
43
44
|
require_relative "html4/sax/parser"
|
44
45
|
require_relative "html4/sax/push_parser"
|
@@ -21,48 +21,137 @@ require_relative "../html4/document"
|
|
21
21
|
|
22
22
|
module Nokogiri
|
23
23
|
module HTML5
|
24
|
+
# Enum for the HTML5 parser quirks mode values. Values returned by HTML5::Document#quirks_mode
|
25
|
+
#
|
26
|
+
# See https://dom.spec.whatwg.org/#concept-document-quirks for more information on HTML5 quirks
|
27
|
+
# mode.
|
28
|
+
#
|
29
|
+
# Since v1.14.0
|
30
|
+
module QuirksMode
|
31
|
+
NO_QUIRKS = 0 # The document was parsed in "no-quirks" mode
|
32
|
+
QUIRKS = 1 # The document was parsed in "quirks" mode
|
33
|
+
LIMITED_QUIRKS = 2 # The document was parsed in "limited-quirks" mode
|
34
|
+
end
|
35
|
+
|
24
36
|
# Since v1.12.0
|
25
37
|
#
|
26
38
|
# 💡 HTML5 functionality is not available when running JRuby.
|
27
39
|
class Document < Nokogiri::HTML4::Document
|
28
|
-
|
29
|
-
|
30
|
-
|
40
|
+
# Get the url name for this document, as passed into Document.parse, Document.read_io, or
|
41
|
+
# Document.read_memory
|
42
|
+
attr_reader :url
|
31
43
|
|
32
|
-
|
33
|
-
|
34
|
-
|
44
|
+
# Get the parser's quirks mode value. See HTML5::QuirksMode.
|
45
|
+
#
|
46
|
+
# This method returns `nil` if the parser was not invoked (e.g., `Nokogiri::HTML5::Document.new`).
|
47
|
+
#
|
48
|
+
# Since v1.14.0
|
49
|
+
attr_reader :quirks_mode
|
35
50
|
|
36
|
-
|
37
|
-
|
51
|
+
class << self
|
52
|
+
# :call-seq:
|
53
|
+
# parse(input)
|
54
|
+
# parse(input, url=nil, encoding=nil, **options)
|
55
|
+
# parse(input, url=nil, encoding=nil) { |options| ... }
|
56
|
+
#
|
57
|
+
# Parse HTML5 input.
|
58
|
+
#
|
59
|
+
# [Parameters]
|
60
|
+
# - +input+ may be a String, or any object that responds to _read_ and _close_ such as an
|
61
|
+
# IO, or StringIO.
|
62
|
+
#
|
63
|
+
# - +url+ (optional) is a String indicating the canonical URI where this document is located.
|
64
|
+
#
|
65
|
+
# - +encoding+ (optional) is the encoding that should be used when processing
|
66
|
+
# the document.
|
67
|
+
#
|
68
|
+
# - +options+ (optional) is a configuration Hash (or keyword arguments) to set options
|
69
|
+
# during parsing. The three currently supported options are +:max_errors+,
|
70
|
+
# +:max_tree_depth+ and +:max_attributes+, described at Nokogiri::HTML5.
|
71
|
+
#
|
72
|
+
# ⚠ Note that these options are different than those made available by
|
73
|
+
# Nokogiri::XML::Document and Nokogiri::HTML4::Document.
|
74
|
+
#
|
75
|
+
# - +block+ (optional) is passed a configuration Hash on which parse options may be set. See
|
76
|
+
# Nokogiri::HTML5 for more information and usage.
|
77
|
+
#
|
78
|
+
# [Returns] Nokogiri::HTML5::Document
|
79
|
+
#
|
80
|
+
def parse(string_or_io, url = nil, encoding = nil, **options, &block)
|
81
|
+
yield options if block
|
82
|
+
string_or_io = "" unless string_or_io
|
83
|
+
|
84
|
+
if string_or_io.respond_to?(:encoding) && string_or_io.encoding != Encoding::ASCII_8BIT
|
85
|
+
encoding ||= string_or_io.encoding.name
|
86
|
+
end
|
87
|
+
|
88
|
+
if string_or_io.respond_to?(:read) && string_or_io.respond_to?(:path)
|
89
|
+
url ||= string_or_io.path
|
90
|
+
end
|
91
|
+
unless string_or_io.respond_to?(:read) || string_or_io.respond_to?(:to_str)
|
92
|
+
raise ArgumentError, "not a string or IO object"
|
93
|
+
end
|
94
|
+
|
95
|
+
do_parse(string_or_io, url, encoding, options)
|
38
96
|
end
|
39
|
-
|
40
|
-
|
97
|
+
|
98
|
+
# Create a new document from an IO object.
|
99
|
+
#
|
100
|
+
# 💡 Most users should prefer Document.parse to this method.
|
101
|
+
def read_io(io, url = nil, encoding = nil, **options)
|
102
|
+
raise ArgumentError, "io object doesn't respond to :read" unless io.respond_to?(:read)
|
103
|
+
|
104
|
+
do_parse(io, url, encoding, options)
|
41
105
|
end
|
42
106
|
|
43
|
-
|
44
|
-
|
107
|
+
# Create a new document from a String.
|
108
|
+
#
|
109
|
+
# 💡 Most users should prefer Document.parse to this method.
|
110
|
+
def read_memory(string, url = nil, encoding = nil, **options)
|
111
|
+
raise ArgumentError, "string object doesn't respond to :to_str" unless string.respond_to?(:to_str)
|
45
112
|
|
46
|
-
|
47
|
-
|
113
|
+
do_parse(string, url, encoding, options)
|
114
|
+
end
|
48
115
|
|
49
|
-
|
50
|
-
end
|
116
|
+
private
|
51
117
|
|
52
|
-
|
53
|
-
|
118
|
+
def do_parse(string_or_io, url, encoding, options)
|
119
|
+
string = HTML5.read_and_encode(string_or_io, encoding)
|
120
|
+
max_attributes = options[:max_attributes] || Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES
|
121
|
+
max_errors = options[:max_errors] || options[:max_parse_errors] || Nokogiri::Gumbo::DEFAULT_MAX_ERRORS
|
122
|
+
max_depth = options[:max_tree_depth] || Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH
|
123
|
+
doc = Nokogiri::Gumbo.parse(string, url, max_attributes, max_errors, max_depth, self)
|
124
|
+
doc.encoding = "UTF-8"
|
125
|
+
doc
|
126
|
+
end
|
127
|
+
end
|
54
128
|
|
55
|
-
|
129
|
+
def initialize(*args) # :nodoc:
|
130
|
+
super
|
131
|
+
@url = nil
|
132
|
+
@quirks_mode = nil
|
56
133
|
end
|
57
134
|
|
58
|
-
|
59
|
-
|
135
|
+
# :call-seq:
|
136
|
+
# fragment() → Nokogiri::HTML5::DocumentFragment
|
137
|
+
# fragment(markup) → Nokogiri::HTML5::DocumentFragment
|
138
|
+
#
|
139
|
+
# Parse a HTML5 document fragment from +markup+, returning a Nokogiri::HTML5::DocumentFragment.
|
140
|
+
#
|
141
|
+
# [Properties]
|
142
|
+
# - +markup+ (String) The HTML5 markup fragment to be parsed
|
143
|
+
#
|
144
|
+
# [Returns]
|
145
|
+
# Nokogiri::HTML5::DocumentFragment. This object's children will be empty if `markup` is not passed, is empty, or is `nil`.
|
146
|
+
#
|
147
|
+
def fragment(markup = nil)
|
148
|
+
DocumentFragment.new(self, markup)
|
60
149
|
end
|
61
150
|
|
62
|
-
def to_xml(options = {}, &block)
|
151
|
+
def to_xml(options = {}, &block) # :nodoc:
|
63
152
|
# Bypass XML::Document#to_xml which doesn't add
|
64
153
|
# XML::Node::SaveOptions::AS_XML like XML::Node#to_xml does.
|
65
|
-
XML::Node.instance_method(:to_xml).
|
154
|
+
XML::Node.instance_method(:to_xml).bind_call(self, options, &block)
|
66
155
|
end
|
67
156
|
|
68
157
|
# :call-seq:
|
@@ -70,22 +159,10 @@ module Nokogiri
|
|
70
159
|
#
|
71
160
|
# [Returns] The document type which determines CSS-to-XPath translation.
|
72
161
|
#
|
73
|
-
# See XPathVisitor for more information.
|
162
|
+
# See CSS::XPathVisitor for more information.
|
74
163
|
def xpath_doctype
|
75
164
|
Nokogiri::CSS::XPathVisitor::DoctypeConfig::HTML5
|
76
165
|
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def self.do_parse(string_or_io, url, encoding, options)
|
81
|
-
string = HTML5.read_and_encode(string_or_io, encoding)
|
82
|
-
max_attributes = options[:max_attributes] || Nokogiri::Gumbo::DEFAULT_MAX_ATTRIBUTES
|
83
|
-
max_errors = options[:max_errors] || options[:max_parse_errors] || Nokogiri::Gumbo::DEFAULT_MAX_ERRORS
|
84
|
-
max_depth = options[:max_tree_depth] || Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH
|
85
|
-
doc = Nokogiri::Gumbo.parse(string, url, max_attributes, max_errors, max_depth)
|
86
|
-
doc.encoding = "UTF-8"
|
87
|
-
doc
|
88
|
-
end
|
89
166
|
end
|
90
167
|
end
|
91
168
|
end
|
@@ -28,8 +28,15 @@ module Nokogiri
|
|
28
28
|
attr_accessor :document
|
29
29
|
attr_accessor :errors
|
30
30
|
|
31
|
+
# Get the parser's quirks mode value. See HTML5::QuirksMode.
|
32
|
+
#
|
33
|
+
# This method returns `nil` if the parser was not invoked (e.g., `Nokogiri::HTML5::DocumentFragment.new(doc)`).
|
34
|
+
#
|
35
|
+
# Since v1.14.0
|
36
|
+
attr_reader :quirks_mode
|
37
|
+
|
31
38
|
# Create a document fragment.
|
32
|
-
def initialize(doc, tags = nil, ctx = nil, options = {})
|
39
|
+
def initialize(doc, tags = nil, ctx = nil, options = {}) # rubocop:disable Lint/MissingSuper
|
33
40
|
self.document = doc
|
34
41
|
self.errors = []
|
35
42
|
return self unless tags
|
@@ -41,10 +48,10 @@ module Nokogiri
|
|
41
48
|
Nokogiri::Gumbo.fragment(self, tags, ctx, max_attributes, max_errors, max_depth)
|
42
49
|
end
|
43
50
|
|
44
|
-
def serialize(options = {}, &block)
|
51
|
+
def serialize(options = {}, &block) # :nodoc:
|
45
52
|
# Bypass XML::Document.serialize which doesn't support options even
|
46
53
|
# though XML::Node.serialize does!
|
47
|
-
XML::Node.instance_method(:serialize).
|
54
|
+
XML::Node.instance_method(:serialize).bind_call(self, options, &block)
|
48
55
|
end
|
49
56
|
|
50
57
|
# Parse a document fragment from +tags+, returning a Nodeset.
|
data/lib/nokogiri/html5/node.rb
CHANGED
@@ -17,6 +17,9 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
+
#
|
21
|
+
# TODO: this whole file should go away. maybe make it a decorator?
|
22
|
+
#
|
20
23
|
require_relative "../xml/node"
|
21
24
|
|
22
25
|
module Nokogiri
|
@@ -28,7 +31,7 @@ module Nokogiri
|
|
28
31
|
def inner_html(options = {})
|
29
32
|
return super(options) unless document.is_a?(HTML5::Document)
|
30
33
|
|
31
|
-
result = options[:preserve_newline] &&
|
34
|
+
result = options[:preserve_newline] && prepend_newline? ? +"\n" : +""
|
32
35
|
result << children.map { |child| child.to_html(options) }.join
|
33
36
|
result
|
34
37
|
end
|
@@ -50,17 +53,17 @@ module Nokogiri
|
|
50
53
|
config = XML::Node::SaveOptions.new(save_options.to_i)
|
51
54
|
yield config if block_given?
|
52
55
|
|
56
|
+
encoding = encoding.is_a?(Encoding) ? encoding.name : encoding
|
57
|
+
|
53
58
|
config_options = config.options
|
54
59
|
if config_options & (XML::Node::SaveOptions::AS_XML | XML::Node::SaveOptions::AS_XHTML) != 0
|
55
60
|
# Use Nokogiri's serializing code.
|
56
61
|
native_write_to(io, encoding, indent_string, config_options)
|
57
62
|
else
|
58
63
|
# Serialize including the current node.
|
64
|
+
html = html_standard_serialize(options[:preserve_newline] || false)
|
59
65
|
encoding ||= document.encoding || Encoding::UTF_8
|
60
|
-
|
61
|
-
preserve_newline: options[:preserve_newline] || false,
|
62
|
-
}
|
63
|
-
HTML5.serialize_node_internal(self, io, encoding, internal_ops)
|
66
|
+
io << html.encode(encoding, fallback: lambda { |c| "&#x#{c.ord.to_s(16)};" })
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|