moxml 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/moxml/adapter/leptris.rb +10 -5
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/adapter/leptris_spec.rb +12 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c0d0117dfa9a9f81f628f2200d09b21d93d148a1dd4d0614c98749c90cdb569e
|
|
4
|
+
data.tar.gz: 85de05e0fe6d7d596b8e39508adbcd98c312b63d16d10eb146caab8f147cdb08
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a57ef921cc44f3706e541abce2bef21b5b9f91066d9bc3528be802a373d57a488fb36825bf13dcf083aa88572fe1d2618ddbbb0d4ebec9a3de93515006698974
|
|
7
|
+
data.tar.gz: db325b0220a05b14bc2e037250c75319a60be30e652d05a1519ea0d26b5ff3afa55031d467312e81388442cb4f172513ef64cfb42be37ddca4c9da4d46704e97
|
|
@@ -859,6 +859,11 @@ module Moxml
|
|
|
859
859
|
# only walks the root subtree, so declaration, DOCTYPE, PIs and
|
|
860
860
|
# document-level text are assembled around it explicitly.
|
|
861
861
|
def serialize_document(doc, options)
|
|
862
|
+
# Nokogiri's document shape: every top-level part is
|
|
863
|
+
# newline-terminated, at any indent — declaration, DOCTYPE,
|
|
864
|
+
# document PIs, the root element, trailing newline after it.
|
|
865
|
+
# Document-level text is content, not structure: no added
|
|
866
|
+
# newline.
|
|
862
867
|
parts = []
|
|
863
868
|
|
|
864
869
|
include_decl = !options[:no_declaration] && options.fetch(:declaration) do
|
|
@@ -866,18 +871,18 @@ module Moxml
|
|
|
866
871
|
end
|
|
867
872
|
if include_decl
|
|
868
873
|
declaration = attachments.get(doc, :declaration)
|
|
869
|
-
parts << (declaration ? declaration.to_xml : default_declaration_xml(doc, options))
|
|
874
|
+
parts << (declaration ? declaration.to_xml : default_declaration_xml(doc, options)) << "\n"
|
|
870
875
|
end
|
|
871
876
|
|
|
872
877
|
doctype = attachments.get(doc, :doctype)
|
|
873
|
-
parts << doctype.to_xml if doctype
|
|
878
|
+
parts << doctype.to_xml << "\n" if doctype
|
|
874
879
|
|
|
875
880
|
native = native_doctype_xml(doc)
|
|
876
|
-
parts << native if native
|
|
881
|
+
parts << native << "\n" if native
|
|
877
882
|
|
|
878
|
-
document_pi_nodes(doc).each { |pi| parts << pi.to_xml }
|
|
883
|
+
document_pi_nodes(doc).each { |pi| parts << pi.to_xml << "\n" }
|
|
879
884
|
|
|
880
|
-
parts << raw_serialize(doc.root, options) if doc.root
|
|
885
|
+
parts << raw_serialize(doc.root, options) << "\n" if doc.root
|
|
881
886
|
|
|
882
887
|
texts = attachments.get(doc, :document_text)
|
|
883
888
|
texts&.each { |text| parts << XmlEmitter.escape_text(text.content.to_s) }
|
data/lib/moxml/version.rb
CHANGED
|
@@ -112,12 +112,22 @@ RSpec.describe Moxml::Adapter::Leptris do
|
|
|
112
112
|
# epilog anchoring); children and to_xml must at least agree.
|
|
113
113
|
doc = ctx.parse('<?xml version="1.0"?><?pi-a 1?><root/><?pi-b 2?>')
|
|
114
114
|
from_children = doc.children.to_a.select(&:processing_instruction?)
|
|
115
|
-
.map(&:to_xml).join
|
|
116
|
-
from_document = doc.to_xml.sub(%r{\A<\?xml[^>]
|
|
115
|
+
.map(&:to_xml).join("\n")
|
|
116
|
+
from_document = doc.to_xml.sub(%r{\A<\?xml[^>]*\?>\n}, "")
|
|
117
117
|
|
|
118
118
|
expect(from_document).to start_with(from_children)
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
+
it "matches raw Nokogiri byte-for-byte for pretty-printing (issue #129)" do
|
|
122
|
+
source = %(<root><a/><b>x</b></root>)
|
|
123
|
+
target = Nokogiri::XML(source).to_xml(indent: 2, encoding: "UTF-8")
|
|
124
|
+
output = ctx.parse(source).to_xml(
|
|
125
|
+
indent: 2, declaration: true, expand_empty: false, encoding: "UTF-8",
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
expect(output).to eq(target)
|
|
129
|
+
end
|
|
130
|
+
|
|
121
131
|
it "reports the tracked native for a re-added document PI" do
|
|
122
132
|
doc = ctx.parse("<?pi-src orig?><root/>")
|
|
123
133
|
moved = doc.children.to_a[0]
|