leptris 1.9.337.0 → 1.9.338.0
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/Rakefile +1 -1
- data/lib/leptris/html.rb +91 -0
- data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
- data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
- data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/document.rb +3 -2
- data/lib/leptris/xml/ffi.rb +6 -1
- data/lib/leptris/xml/serialization.rb +23 -3
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +12 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/src/include/leptris/types.h +8 -0
- data/vendor-src/libleptris/src/leptris/html/html_parse.c +31 -8
- data/vendor-src/libleptris/src/leptris/serialize/serialize.c +56 -13
- data/vendor-src/libleptris/src/leptris/serialize/serialize.h +4 -0
- data/vendor-src/libleptris/test/serializer/test_serialize.cpp +93 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- 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: 61e4519004125fc7476bfd1055fdf3e88de5cc049c7d2a56dc277beee10d38b9
|
|
4
|
+
data.tar.gz: f522623cdf717c5eb24d7c37a65eb4243aa438d28253104cc0e276013aaaa480
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fa808fd813407ce2370d675a27cd94b1445cf050c53905c13579ff78fd9b0ac99c665e0cbf4355267b224e4620fb6598ae045c47566ac8a29f71d00bca2cb6f
|
|
7
|
+
data.tar.gz: e3e974c246002ccdb8bd2bbc3c37b39ff4cb152fe4b690028ec4b6b87fd024fd581d031d99a97fde940846fa2d28fba6225866e2df2d4ca855aa82a2d182b649
|
data/Rakefile
CHANGED
|
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
|
8
8
|
# Pin for `rake compile` and the platform-gem builds. Keep in lockstep
|
|
9
9
|
# with .github/workflows/build.yml (which calls `rake compile`) and the
|
|
10
10
|
# CHANGELOG when libleptris releases.
|
|
11
|
-
LIBLEPTRIS_VERSION = "1.9.
|
|
11
|
+
LIBLEPTRIS_VERSION = "1.9.338"
|
|
12
12
|
# Vendored alongside libleptris for fn:normalize-unicode (TODO
|
|
13
13
|
# .restructure/20): built per platform with a RELOCATABLE @rpath
|
|
14
14
|
# install name, loaded by ffi.rb before libleptris so the
|
data/lib/leptris/html.rb
CHANGED
|
@@ -21,6 +21,78 @@
|
|
|
21
21
|
# elements serialize with the HTML5-legal trailing slash).
|
|
22
22
|
module Leptris
|
|
23
23
|
module HTML
|
|
24
|
+
# WHATWG fragment parsing with a context element (#1634 /
|
|
25
|
+
# moxml#353). Composed over the WHATWG lane: the fragment runs
|
|
26
|
+
# inside the context element's ancestor chain, so tree
|
|
27
|
+
# construction lands in the right insertion mode (body context
|
|
28
|
+
# keeps <title>/<meta> at fragment top level; table contexts
|
|
29
|
+
# take the in-table rules). The wrapper document stays alive
|
|
30
|
+
# for the fragment's lifetime - children address its pool.
|
|
31
|
+
class Fragment
|
|
32
|
+
# chains are the ancestors the parser opens before the
|
|
33
|
+
# fragment: the innermost element carries the children
|
|
34
|
+
TABLE_CHAINS = {
|
|
35
|
+
table: %w[table],
|
|
36
|
+
tbody: %w[table tbody],
|
|
37
|
+
thead: %w[table thead],
|
|
38
|
+
tfoot: %w[table tfoot],
|
|
39
|
+
tr: %w[table tbody tr],
|
|
40
|
+
td: %w[table tbody tr td],
|
|
41
|
+
th: %w[table tbody tr th],
|
|
42
|
+
caption: %w[table caption],
|
|
43
|
+
colgroup: %w[table colgroup],
|
|
44
|
+
}.freeze
|
|
45
|
+
|
|
46
|
+
def initialize(document, chain)
|
|
47
|
+
# The wrapper document always carries a body (explicit tag
|
|
48
|
+
# or synthesis); table chains nest under it.
|
|
49
|
+
@document = document
|
|
50
|
+
el = first_element_named(document.root, "body")
|
|
51
|
+
chain.each do |tag|
|
|
52
|
+
break unless el
|
|
53
|
+
el = first_element_named(el, tag)
|
|
54
|
+
end
|
|
55
|
+
@context = el
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The parsed top-level nodes (text, elements, comments) in
|
|
59
|
+
# tree order - the fragment's children, Nokogiri's
|
|
60
|
+
# DocumentFragment#children shape.
|
|
61
|
+
def children
|
|
62
|
+
@context ? @context.children.to_a : []
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def each(&block)
|
|
66
|
+
children.each(&block)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
include Enumerable
|
|
70
|
+
|
|
71
|
+
def size
|
|
72
|
+
children.size
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def empty?
|
|
76
|
+
children.empty?
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# The fragment serialized as its children joined (HTML
|
|
80
|
+
# method per node; text verbatim).
|
|
81
|
+
def to_html
|
|
82
|
+
children.map do |c|
|
|
83
|
+
c.is_a?(Leptris::XML::Text) ? c.content : c.to_html
|
|
84
|
+
end.join
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def first_element_named(parent, name)
|
|
90
|
+
parent.children.find do |c|
|
|
91
|
+
c.is_a?(Leptris::XML::Element) && c.name == name
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
24
96
|
module_function
|
|
25
97
|
|
|
26
98
|
# Nokogiri::HTML shape: the default lane is html4 (byte-parity
|
|
@@ -29,6 +101,25 @@ module Leptris
|
|
|
29
101
|
Leptris::XML.parse_html(html, mode: :html4)
|
|
30
102
|
end
|
|
31
103
|
|
|
104
|
+
# WHATWG fragment parse (body context by default; the table
|
|
105
|
+
# contexts wrap their ancestor chain). Matches
|
|
106
|
+
# Nokogiri::HTML5.fragment semantics on the head-sweep and
|
|
107
|
+
# foster-parenting divergence set (verified against the
|
|
108
|
+
# html5lib trees).
|
|
109
|
+
def parse_fragment(html, context: :body)
|
|
110
|
+
chain = context == :body ? ["body"] : Fragment::TABLE_CHAINS.fetch(context) do
|
|
111
|
+
raise ArgumentError,
|
|
112
|
+
"context must be :body or a table context " \
|
|
113
|
+
"(#{(Fragment::TABLE_CHAINS.keys + [:body]).join(', ')}), " \
|
|
114
|
+
"got #{context.inspect}"
|
|
115
|
+
end
|
|
116
|
+
prefix = "<body>#{chain.map { |t| "<#{t}>" }.join}"
|
|
117
|
+
suffix = "#{chain.reverse.map { |t| "</#{t}>" }.join}</body>"
|
|
118
|
+
wrapped = "#{prefix}#{html}#{suffix}"
|
|
119
|
+
Fragment.new(Leptris::HTML5.parse(wrapped),
|
|
120
|
+
chain.first == "body" ? chain.drop(1) : chain)
|
|
121
|
+
end
|
|
122
|
+
|
|
32
123
|
# Fresh document with the HTML 4.01 Transitional doctype preset
|
|
33
124
|
# (Nokogiri::HTML::Builder's .doc carries the same). Pass
|
|
34
125
|
# +doctype: nil+ for a bare document.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/leptris/version.rb
CHANGED
data/lib/leptris/xml/document.rb
CHANGED
|
@@ -546,9 +546,10 @@ class Leptris::XML::Document
|
|
|
546
546
|
# entity escaping per HTML rules, the DOCTYPE emitted first.
|
|
547
547
|
# Walks the tree in Ruby — the engine-side serialization mode is
|
|
548
548
|
# the perf headroom this face gates on.
|
|
549
|
-
def to_html
|
|
549
|
+
def to_html(indent: 0, indent_text: nil)
|
|
550
550
|
raise Leptris::XML::UseAfterFreeError if @freed.state == :freed
|
|
551
|
-
Leptris::XML::Serialization.document_html(
|
|
551
|
+
Leptris::XML::Serialization.document_html(
|
|
552
|
+
c_ptr, indent: indent, indent_text: indent_text)
|
|
552
553
|
end
|
|
553
554
|
|
|
554
555
|
def save(path, mode: :xml, **opts)
|
data/lib/leptris/xml/ffi.rb
CHANGED
|
@@ -205,7 +205,12 @@ module Leptris
|
|
|
205
205
|
# libleptris 1.9.225 (#1311): tri-state — 0 = the
|
|
206
206
|
# document's default method, 1 = force HTML, -1 =
|
|
207
207
|
# force XML (to_xml on an HTML document).
|
|
208
|
-
:html_method, :int
|
|
208
|
+
:html_method, :int,
|
|
209
|
+
# libleptris 1.9.xxx (#1635): 1 = the html layout
|
|
210
|
+
# nests with the indent machinery (libxml2 format
|
|
211
|
+
# mode); 0 = the §16.2 newline-only shape. Appended —
|
|
212
|
+
# the sized entry keeps older allocations zeroed.
|
|
213
|
+
:indent_html, :int
|
|
209
214
|
end
|
|
210
215
|
|
|
211
216
|
# Mirrors LeptrisParseOptions (libleptris >= 1.9.0 carries the
|
|
@@ -60,10 +60,30 @@ module Leptris::XML::Serialization
|
|
|
60
60
|
# one FFI fast-path dispatch per child.
|
|
61
61
|
# Document HTML serialization (libleptris 1.9.225, #1311): the
|
|
62
62
|
# native HTML mode — voids unclosed, raw-text script/style,
|
|
63
|
-
# explicit closes, no declaration, DOCTYPE first.
|
|
64
|
-
|
|
63
|
+
# explicit closes, no declaration, DOCTYPE first. With +indent+
|
|
64
|
+
# (spaces per level) or +indent_text+ (a unit string like "\t"),
|
|
65
|
+
# the ext serializer runs method="html" layout over the standard
|
|
66
|
+
# indent machinery (moxml#354 / leptris#1635): line breaks around
|
|
67
|
+
# block/element children per the HTML element table, raw-text and
|
|
68
|
+
# mixed content verbatim.
|
|
69
|
+
def self.document_html(c_ptr, indent: 0, indent_text: nil)
|
|
70
|
+
if indent.to_i.zero? && indent_text.nil?
|
|
71
|
+
return Leptris::XML::FFI.read_owned_string(
|
|
72
|
+
Leptris::XML::FFI.leptris_document_serialize_html(c_ptr, nil))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
opts, _encoding_anchor = build_options(indent: indent, no_decl: true)
|
|
76
|
+
ext = Leptris::XML::FFI::SerializeExtStruct.new
|
|
77
|
+
ext[:html_method] = 1
|
|
78
|
+
ext[:indent_html] = 1
|
|
79
|
+
unit_anchor = nil
|
|
80
|
+
if indent_text
|
|
81
|
+
unit_anchor = ::FFI::MemoryPointer.from_string(indent_text.to_s)
|
|
82
|
+
ext[:indent_unit] = unit_anchor
|
|
83
|
+
end
|
|
65
84
|
Leptris::XML::FFI.read_owned_string(
|
|
66
|
-
Leptris::XML::FFI.
|
|
85
|
+
Leptris::XML::FFI.leptris_document_serialize_ext_sized(
|
|
86
|
+
c_ptr, opts.pointer, ext.pointer, ext.size))
|
|
67
87
|
end
|
|
68
88
|
|
|
69
89
|
# Element-level HTML mode through the ext serializer (the
|
data/vendor-src/README.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [1.9.338] - 2026-10-11
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- indent_html ext option — nested HTML indent (#1635) (serialize)
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- in-body drops the table-structure start tags (#1634) (html)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## [1.9.337] - 2026-10-11
|
|
4
16
|
|
|
5
17
|
### Added
|
|
@@ -360,6 +360,14 @@ typedef struct {
|
|
|
360
360
|
* 1 = force HTML on any document, -1 = force XML (to_xml on an
|
|
361
361
|
* HTML document). XSLT method="html" maps to 1. */
|
|
362
362
|
int html_method;
|
|
363
|
+
/* 1 = the html-method layout NESTS with the indent machinery
|
|
364
|
+
* (spaces / unit) like libxml2 htmlNodeDumpFormatOutput
|
|
365
|
+
* format=1 (#1635): leads before block children and close tags,
|
|
366
|
+
* mixed follows actual text children, raw text stays verbatim.
|
|
367
|
+
* 0 = the historical §16.2 newline-only shape (XSLT
|
|
368
|
+
* method="html"). Meaningful only with html_method=1 and
|
|
369
|
+
* options->indent > 0. */
|
|
370
|
+
int indent_html;
|
|
363
371
|
} LeptrisSerializeExtOptions;
|
|
364
372
|
|
|
365
373
|
/* ============================================================================
|
|
@@ -7213,23 +7213,46 @@ static LeptrisDocument html_parse_shared(
|
|
|
7213
7213
|
continue;
|
|
7214
7214
|
}
|
|
7215
7215
|
|
|
7216
|
-
/*
|
|
7217
|
-
*
|
|
7218
|
-
*
|
|
7219
|
-
*
|
|
7216
|
+
/* Table-structure-only start tags in body drop - "in
|
|
7217
|
+
* body" has no insertion rule for caption, col, colgroup,
|
|
7218
|
+
* head, tbody, td, tfoot, th, thead, tr (WHATWG 13.2.6.4
|
|
7219
|
+
* "any other start tag" path: parse error, ignore the
|
|
7220
|
+
* token, its content flows into body; tests25:7
|
|
7221
|
+
* <body><col>A keeps just "A", tests1:109's trailing
|
|
7222
|
+
* <colgroup> after </table> vanishes). Valid inside a
|
|
7223
|
+
* table/colgroup/template context - the in-table machinery
|
|
7224
|
+
* owns them there. */
|
|
7220
7225
|
if (b.whatwg &&
|
|
7221
7226
|
(strcmp(name, "col") == 0 ||
|
|
7222
|
-
strcmp(name, "colgroup") == 0
|
|
7223
|
-
|
|
7227
|
+
strcmp(name, "colgroup") == 0 ||
|
|
7228
|
+
strcmp(name, "caption") == 0 ||
|
|
7229
|
+
strcmp(name, "head") == 0 ||
|
|
7230
|
+
strcmp(name, "tbody") == 0 ||
|
|
7231
|
+
strcmp(name, "td") == 0 ||
|
|
7232
|
+
strcmp(name, "tfoot") == 0 ||
|
|
7233
|
+
strcmp(name, "th") == 0 ||
|
|
7234
|
+
strcmp(name, "thead") == 0 ||
|
|
7235
|
+
strcmp(name, "tr") == 0)) {
|
|
7236
|
+
/* Foreign content inserts any start tag (the svg/math
|
|
7237
|
+
* breakout list does not include these names) — the
|
|
7238
|
+
* drop is an "in body" rule only. */
|
|
7239
|
+
int tbl_ctx = h_top_foreign(&b) ? 1 : 0;
|
|
7224
7240
|
for (size_t d2 = b.depth; d2 > 0; d2--) {
|
|
7225
7241
|
uint8_t oid2 = b.open_id[d2 - 1];
|
|
7226
7242
|
if (oid2 == h_id_table || oid2 == h_id_colgroup ||
|
|
7227
7243
|
oid2 == h_id_template) {
|
|
7228
|
-
|
|
7244
|
+
tbl_ctx = 1;
|
|
7229
7245
|
break;
|
|
7230
7246
|
}
|
|
7231
7247
|
}
|
|
7232
|
-
if (!
|
|
7248
|
+
if (!tbl_ctx) {
|
|
7249
|
+
/* The TOKEN is ignored - surrounding character
|
|
7250
|
+
* tokens keep flowing into body (the html-merge
|
|
7251
|
+
* flush pattern). */
|
|
7252
|
+
if (text < p) {
|
|
7253
|
+
LeptrisTextNode* t = h_text_node(&b, text, p);
|
|
7254
|
+
if (t) h_append(&b, (LeptrisNodeRef)t);
|
|
7255
|
+
}
|
|
7233
7256
|
while (q < end && *q != '>') q++;
|
|
7234
7257
|
p = (q < end) ? q + 1 : end;
|
|
7235
7258
|
text = p;
|
|
@@ -48,6 +48,7 @@ SerializeBuffer* buffer_create(int indent_spaces) {
|
|
|
48
48
|
buf->indent_spaces = indent_spaces;
|
|
49
49
|
buf->indent_unit = NULL; /* #633: callers opt in per unit string */
|
|
50
50
|
buf->html_method = 0;
|
|
51
|
+
buf->indent_html = 0;
|
|
51
52
|
buf->indent_text = 0;
|
|
52
53
|
buf->expand_empty = 0;
|
|
53
54
|
buf->at_line_start = 0;
|
|
@@ -135,9 +136,11 @@ void buffer_append_char(SerializeBuffer* buf, char c) {
|
|
|
135
136
|
|
|
136
137
|
void buffer_append_indent(SerializeBuffer* buf) {
|
|
137
138
|
if (!buf || buf->indent_spaces <= 0) return;
|
|
138
|
-
/* §16.2 html method: newline-only
|
|
139
|
-
* never nests
|
|
140
|
-
|
|
139
|
+
/* §16.2 html method: the historical layout is newline-only —
|
|
140
|
+
* libxml2's unindented HTML dump never nests. #1635
|
|
141
|
+
* indent_html opts the html method into the nesting layout
|
|
142
|
+
* (htmlNodeDumpFormatOutput format=1). */
|
|
143
|
+
if (buf->html_method && !buf->indent_html) return;
|
|
141
144
|
|
|
142
145
|
if (buf->indent_unit && buf->indent_unit[0]) {
|
|
143
146
|
size_t ul = strlen(buf->indent_unit);
|
|
@@ -1015,7 +1018,8 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
|
|
|
1015
1018
|
* inside a mixed parent is verbatim content: never
|
|
1016
1019
|
* dropped. HTML mode prints text verbatim (libxml2 has
|
|
1017
1020
|
* no formatter-owned whitespace there). */
|
|
1018
|
-
if (buf->indent_spaces > 0 &&
|
|
1021
|
+
if (buf->indent_spaces > 0 &&
|
|
1022
|
+
(!buf->html_method || buf->indent_html) &&
|
|
1019
1023
|
cur->type == LEPTRIS_NODE_TYPE_TEXT &&
|
|
1020
1024
|
!((sp > 0) && st[sp - 1].mixed)) {
|
|
1021
1025
|
LeptrisTextNode* wsn = (LeptrisTextNode*)cur;
|
|
@@ -1102,7 +1106,7 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
|
|
|
1102
1106
|
* line, like element siblings. Mixed-content parents
|
|
1103
1107
|
* keep them inline — a PI between text must not move. */
|
|
1104
1108
|
if (buf->indent_spaces > 0 && sp > 0 && !st[sp - 1].mixed &&
|
|
1105
|
-
!buf->html_method &&
|
|
1109
|
+
(!buf->html_method || buf->indent_html) &&
|
|
1106
1110
|
(cur->type == LEPTRIS_NODE_TYPE_COMMENT ||
|
|
1107
1111
|
cur->type == LEPTRIS_NODE_TYPE_PI)) {
|
|
1108
1112
|
buffer_append_indent(buf);
|
|
@@ -1183,8 +1187,8 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
|
|
|
1183
1187
|
* close into the same single reservation — leaves
|
|
1184
1188
|
* otherwise pay ~8 capacity-checked appends each
|
|
1185
1189
|
* (the raw-only guard was why pretty trailed). */
|
|
1186
|
-
int pretty0 = buf->indent_spaces > 0 &&
|
|
1187
|
-
!buf->html_method
|
|
1190
|
+
int pretty0 = buf->indent_spaces > 0 && !parent_mixed &&
|
|
1191
|
+
(!buf->html_method || buf->indent_html);
|
|
1188
1192
|
/* HTML mode: zero lead ever; trail follows the
|
|
1189
1193
|
* after-close break rule (mixed is not a gate). */
|
|
1190
1194
|
int htrail0 = buf->html_method && !is_root_cur &&
|
|
@@ -1619,12 +1623,32 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
|
|
|
1619
1623
|
int mixed = 0;
|
|
1620
1624
|
int close_brk = 0;
|
|
1621
1625
|
if (buf->html_method) {
|
|
1622
|
-
/* §16.2: mixed is not a gate — the site rules own the
|
|
1623
|
-
* newlines. mixed=1 keeps ws-only text verbatim. */
|
|
1624
|
-
mixed = 1;
|
|
1625
1626
|
int hf = html_elem_sem_flags(e);
|
|
1626
|
-
if (
|
|
1627
|
-
|
|
1627
|
+
if (!buf->indent_html) {
|
|
1628
|
+
/* §16.2 legacy: mixed is not a gate — the site
|
|
1629
|
+
* rules own the newlines. mixed=1 keeps ws-only
|
|
1630
|
+
* text verbatim. */
|
|
1631
|
+
mixed = 1;
|
|
1632
|
+
if (html_break_before_children(e, name, nl, hf))
|
|
1633
|
+
buffer_append_newline(buf);
|
|
1634
|
+
} else {
|
|
1635
|
+
/* #1635 indented HTML: the element takes the block
|
|
1636
|
+
* layout — mixed follows actual text children like
|
|
1637
|
+
* the XML formatter (libxml2 format mode), so the
|
|
1638
|
+
* layout machinery nests; the site rules still own
|
|
1639
|
+
* the newlines. Elements that keep their children
|
|
1640
|
+
* inline (single-child rule) own no whitespace. */
|
|
1641
|
+
int brk_bc = html_break_before_children(e, name, nl, hf);
|
|
1642
|
+
if (brk_bc) {
|
|
1643
|
+
mixed = buf->ws_mixed
|
|
1644
|
+
? ser_children_have_any_text(fc)
|
|
1645
|
+
: ser_children_have_text(fc);
|
|
1646
|
+
if (!mixed && sp > 0 && st[sp - 1].mixed) mixed = 1;
|
|
1647
|
+
} else {
|
|
1648
|
+
mixed = 1;
|
|
1649
|
+
}
|
|
1650
|
+
if (brk_bc) buffer_append_newline(buf);
|
|
1651
|
+
}
|
|
1628
1652
|
close_brk = html_break_before_close(e, name, nl, hf);
|
|
1629
1653
|
} else {
|
|
1630
1654
|
/* #129 indent_text: the formatter owns ALL whitespace —
|
|
@@ -1698,8 +1722,19 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
|
|
|
1698
1722
|
const char* pfx2 = leptris_element_get_prefix(pe);
|
|
1699
1723
|
/* #534: no indent inside a mixed-content element. HTML
|
|
1700
1724
|
* mode: site-3 newline before the close tag, no spaces. */
|
|
1701
|
-
if (buf->html_method) {
|
|
1725
|
+
if (buf->html_method && !buf->indent_html) {
|
|
1702
1726
|
if (st[sp].close_brk) buffer_append_newline(buf);
|
|
1727
|
+
} else if (buf->html_method) {
|
|
1728
|
+
/* #1635: the last child's after-close break may
|
|
1729
|
+
* already have ended the line — dedup so the close
|
|
1730
|
+
* tag nests without a blank line. */
|
|
1731
|
+
if (st[sp].close_brk && buf->size > 0 &&
|
|
1732
|
+
buf->data[buf->size - 1] == '\n') {
|
|
1733
|
+
buffer_append_indent(buf);
|
|
1734
|
+
} else if (st[sp].close_brk) {
|
|
1735
|
+
buffer_append_newline(buf);
|
|
1736
|
+
buffer_append_indent(buf);
|
|
1737
|
+
}
|
|
1703
1738
|
} else if (buf->indent_spaces > 0 && !st[sp].mixed) {
|
|
1704
1739
|
buffer_append_indent(buf);
|
|
1705
1740
|
}
|
|
@@ -1891,6 +1926,9 @@ LEPTRIS_API char* leptris_document_serialize_ext_sized(
|
|
|
1891
1926
|
if (ext_size >= offsetof(LeptrisSerializeExtOptions, html_method) +
|
|
1892
1927
|
sizeof(int))
|
|
1893
1928
|
internal.html_method = ext->html_method;
|
|
1929
|
+
if (ext_size >= offsetof(LeptrisSerializeExtOptions, indent_html) +
|
|
1930
|
+
sizeof(int))
|
|
1931
|
+
internal.indent_html = ext->indent_html;
|
|
1894
1932
|
}
|
|
1895
1933
|
return leptris_document_serialize_ex(doc, options, &internal);
|
|
1896
1934
|
}
|
|
@@ -1926,6 +1964,9 @@ LEPTRIS_API char* leptris_element_serialize_ext_sized(
|
|
|
1926
1964
|
if (ext_size >= offsetof(LeptrisSerializeExtOptions, html_method) +
|
|
1927
1965
|
sizeof(int))
|
|
1928
1966
|
internal.html_method = ext->html_method;
|
|
1967
|
+
if (ext_size >= offsetof(LeptrisSerializeExtOptions, indent_html) +
|
|
1968
|
+
sizeof(int))
|
|
1969
|
+
internal.indent_html = ext->indent_html;
|
|
1929
1970
|
}
|
|
1930
1971
|
return leptris_element_serialize_ex(elem, options, &internal);
|
|
1931
1972
|
}
|
|
@@ -1946,6 +1987,7 @@ char* leptris_element_serialize_ex(LeptrisElement elem,
|
|
|
1946
1987
|
buf->cdata_names = extended->cdata_elements;
|
|
1947
1988
|
buf->cdata_count = extended->cdata_element_count;
|
|
1948
1989
|
buf->html_method = extended->html_method != 0;
|
|
1990
|
+
buf->indent_html = extended->indent_html != 0;
|
|
1949
1991
|
buf->indent_text = extended->indent_text != 0;
|
|
1950
1992
|
buf->expand_empty = extended->expand_empty != 0;
|
|
1951
1993
|
buf->indent_unit = extended->indent_unit;
|
|
@@ -2010,6 +2052,7 @@ char* leptris_document_serialize_ex(struct leptris_document* doc,
|
|
|
2010
2052
|
* force XML (Nokogiri's to_xml-on-HTML-doc). */
|
|
2011
2053
|
if (extended->html_method == -1) buf->html_method = 0;
|
|
2012
2054
|
else if (extended->html_method == 1) buf->html_method = 1;
|
|
2055
|
+
buf->indent_html = extended->indent_html != 0;
|
|
2013
2056
|
buf->indent_text = extended->indent_text != 0;
|
|
2014
2057
|
buf->expand_empty = extended->expand_empty != 0;
|
|
2015
2058
|
buf->indent_unit = extended->indent_unit;
|
|
@@ -77,6 +77,9 @@ typedef struct SerializeBuffer {
|
|
|
77
77
|
/* §16.2 method="html": newline-per-block-element layout governed
|
|
78
78
|
* by the HTML element table (html_elem_flags). */
|
|
79
79
|
int html_method;
|
|
80
|
+
/* #1635: html layout nests with the indent machinery (0 = the
|
|
81
|
+
* §16.2 newline-only shape). */
|
|
82
|
+
int indent_html;
|
|
80
83
|
/* libxml2 XHTML serialization (xmlsave.c xhtmlNodeDumpOutput
|
|
81
84
|
* parity): an xml-method result whose doctype ids match an XHTML
|
|
82
85
|
* DTD injects the Content-Type meta into the root html/head and
|
|
@@ -138,6 +141,7 @@ typedef struct {
|
|
|
138
141
|
/* Indent unit string (#633): one copy per depth level; NULL =
|
|
139
142
|
* indent_spaces spaces per level. */
|
|
140
143
|
const char* indent_unit;
|
|
144
|
+
int indent_html; /* #1635: nested html indent (§16.2 default 0) */
|
|
141
145
|
} LeptrisSerializeExtended;
|
|
142
146
|
|
|
143
147
|
LEPTRIS_API char* leptris_document_serialize_ext(
|
|
@@ -760,6 +760,99 @@ TEST(SerializeOptions, IndentUnitOnTextBearingLeaves) {
|
|
|
760
760
|
leptris_document_free(doc);
|
|
761
761
|
}
|
|
762
762
|
|
|
763
|
+
/* Issue #1635: indent_html — the html-method layout nests with
|
|
764
|
+
* the indent machinery (libxml2 htmlNodeDumpFormatOutput format=1):
|
|
765
|
+
* leads before block children and close tags, single-child
|
|
766
|
+
* elements stay inline, raw text verbatim. The §16.2 default
|
|
767
|
+
* (XSLT method="html") stays newline-only. */
|
|
768
|
+
static char* html_force_serialize(LeptrisDocument doc, int indent,
|
|
769
|
+
int indent_html, int ext_bytes) {
|
|
770
|
+
LeptrisSerializeOptions opts = {0};
|
|
771
|
+
opts.indent = indent;
|
|
772
|
+
opts.xml_declaration = 0;
|
|
773
|
+
LeptrisSerializeExtOptions ext = {0};
|
|
774
|
+
ext.html_method = 1;
|
|
775
|
+
ext.indent_html = indent_html;
|
|
776
|
+
return leptris_document_serialize_ext_sized(
|
|
777
|
+
doc, &opts, &ext,
|
|
778
|
+
ext_bytes > 0 ? (size_t)ext_bytes : sizeof(ext));
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
TEST(SerializeOptions, IndentHtmlNestsBlockChildren) {
|
|
782
|
+
const char xml[] = "<html><head><title>T</title></head><body>"
|
|
783
|
+
"<div id=\"a\"><p>x</p><span>y</span></div>"
|
|
784
|
+
"<script>if (a < b) { c(); }</script></body></html>";
|
|
785
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
786
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
787
|
+
ASSERT_NE(doc, nullptr);
|
|
788
|
+
char* s = html_force_serialize(doc, 2, 1, 0);
|
|
789
|
+
ASSERT_NE(s, nullptr);
|
|
790
|
+
EXPECT_EQ(std::string(s),
|
|
791
|
+
"<html>\n"
|
|
792
|
+
" <head><title>T</title></head>\n"
|
|
793
|
+
" <body>\n"
|
|
794
|
+
" <div id=\"a\">\n"
|
|
795
|
+
" <p>x</p>\n"
|
|
796
|
+
" <span>y</span>\n"
|
|
797
|
+
" </div>\n"
|
|
798
|
+
" <script>if (a < b) { c(); }</script>\n"
|
|
799
|
+
" </body>\n"
|
|
800
|
+
"</html>");
|
|
801
|
+
leptris_free_string(s);
|
|
802
|
+
leptris_document_free(doc);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
TEST(SerializeOptions, IndentHtmlLegacyStaysNewlineOnly) {
|
|
806
|
+
const char xml[] = "<html><body><div><p>one</p><p>two</p></div>"
|
|
807
|
+
"</body></html>";
|
|
808
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
809
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
810
|
+
ASSERT_NE(doc, nullptr);
|
|
811
|
+
char* s = html_force_serialize(doc, 2, 0, 0);
|
|
812
|
+
ASSERT_NE(s, nullptr);
|
|
813
|
+
/* §16.2 byte shape: site-rule newlines, never a space lead —
|
|
814
|
+
* single-child wrappers (html>body>div) keep the inline chain,
|
|
815
|
+
* only multi-child blocks break. */
|
|
816
|
+
EXPECT_EQ(std::string(s),
|
|
817
|
+
"<html><body><div>\n"
|
|
818
|
+
"<p>one</p>\n"
|
|
819
|
+
"<p>two</p>\n"
|
|
820
|
+
"</div></body></html>");
|
|
821
|
+
leptris_free_string(s);
|
|
822
|
+
leptris_document_free(doc);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
TEST(SerializeOptions, IndentHtmlNotReadPastCallerLayout) {
|
|
826
|
+
/* #644 shape: a caller compiled against the pre-#1635 layout
|
|
827
|
+
* covers exactly through html_method (24 bytes) — the appended
|
|
828
|
+
* field stays zeroed and the output keeps the legacy shape. */
|
|
829
|
+
const char xml[] = "<html><body><div><p>x</p></div></body></html>";
|
|
830
|
+
LeptrisStatus st = LEPTRIS_OK;
|
|
831
|
+
LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
|
|
832
|
+
ASSERT_NE(doc, nullptr);
|
|
833
|
+
const size_t legacy_size =
|
|
834
|
+
offsetof(LeptrisSerializeExtOptions, html_method) + sizeof(int);
|
|
835
|
+
unsigned char raw[64];
|
|
836
|
+
memset(raw, 0x5A, sizeof(raw));
|
|
837
|
+
LeptrisSerializeExtOptions* ext = (LeptrisSerializeExtOptions*)raw;
|
|
838
|
+
ext->indent_text = 0;
|
|
839
|
+
ext->indent_unit = nullptr;
|
|
840
|
+
ext->expand_empty = 0;
|
|
841
|
+
ext->html_method = 1;
|
|
842
|
+
LeptrisSerializeOptions opts = {0};
|
|
843
|
+
opts.indent = 2;
|
|
844
|
+
opts.xml_declaration = 0;
|
|
845
|
+
char* s = leptris_document_serialize_ext_sized(
|
|
846
|
+
doc, &opts, ext, legacy_size);
|
|
847
|
+
ASSERT_NE(s, nullptr);
|
|
848
|
+
char* want = html_force_serialize(doc, 2, 0, 0);
|
|
849
|
+
ASSERT_NE(want, nullptr);
|
|
850
|
+
EXPECT_EQ(std::string(s), std::string(want));
|
|
851
|
+
leptris_free_string(s);
|
|
852
|
+
leptris_free_string(want);
|
|
853
|
+
leptris_document_free(doc);
|
|
854
|
+
}
|
|
855
|
+
|
|
763
856
|
/* Issue #644: FFI callers allocate only the fields they know — the
|
|
764
857
|
* sized entry must not read past their buffer. The Ruby binding's
|
|
765
858
|
* layout is exactly one int (indent_text): a 4-byte ext with garbage
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
|
3
3
|
"name": "leptris",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.338",
|
|
5
5
|
"description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
|
|
6
6
|
"homepage": "https://github.com/leptris/leptris",
|
|
7
7
|
"license": "MIT",
|