pyhtml2text 0.4.0__tar.gz → 0.4.2__tar.gz
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.
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/.gitignore +1 -1
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/CHANGELOG.md +26 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/Cargo.lock +33 -32
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/Cargo.toml +5 -4
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/PKG-INFO +16 -3
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/README.md +5 -2
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/pyproject.toml +11 -1
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/src/table.rs +7 -18
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/src/text.rs +77 -32
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/tests/test_basic.py +24 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/README.md +14 -12
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/Cargo.toml +5 -10
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/encoding.rs +51 -1
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/serialize/mod.rs +43 -9
- pyhtml2text-0.4.2/vendor/html5ever/src/tokenizer/mod.rs +3292 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tree_builder/mod.rs +13 -21
- pyhtml2text-0.4.0/vendor/html5ever/src/tokenizer/mod.rs +0 -2324
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/LICENSE +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/python/pyhtml2text/__init__.py +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/python/pyhtml2text/__init__.pyi +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/python/pyhtml2text/py.typed +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/src/dom.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/src/lib.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/src/markdown.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/src/url.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/tests/markdown_check.py +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/tests/test_markdown.py +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/LICENSE-APACHE +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/LICENSE-MIT +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/README.md +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/driver.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/lib.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/macros.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tokenizer/char_ref/mod.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tokenizer/interface.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tokenizer/states.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tree_builder/data.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tree_builder/open_elems.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tree_builder/rules.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tree_builder/tag_sets.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/tree_builder/types.rs +0 -0
- {pyhtml2text-0.4.0 → pyhtml2text-0.4.2}/vendor/html5ever/src/util/str.rs +0 -0
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.2 (2026-11-22)
|
|
4
|
+
|
|
5
|
+
- Rust dependencies updated to their newest compatible versions
|
|
6
|
+
(pulldown-cmark 0.13.6, smallvec 1.16.6, log 0.4.35; build tools cc,
|
|
7
|
+
syn and target-lexicon). PyO3 stays 0.30.1 and html5ever the vendored
|
|
8
|
+
0.40.1 with [servo/html5ever#800](https://github.com/servo/html5ever/pull/800),
|
|
9
|
+
both the newest releases. Output is unchanged.
|
|
10
|
+
|
|
11
|
+
## 0.4.1 (2026-10-30)
|
|
12
|
+
|
|
13
|
+
- Deeply nested lists, definitions, paragraphs and emphasis are rendered in
|
|
14
|
+
linear time again. In 0.4.0 each level cost time for every level around
|
|
15
|
+
it: 400,000 nested lists took 49 s, and now take 0.5 s. Output is
|
|
16
|
+
unchanged.
|
|
17
|
+
- Wheels for free-threaded Python 3.15 (3.15t), alongside 3.14t. The abi3
|
|
18
|
+
wheels already cover Python 3.15. CI now tests on 3.10, 3.14t, 3.15 and
|
|
19
|
+
3.15t.
|
|
20
|
+
- Character widths from Unicode 18 (unicode-width 0.2.3). The halfwidth
|
|
21
|
+
katakana sound marks ゙ and ゚ count one column, as terminals show them,
|
|
22
|
+
rather than none, and characters new in Unicode 18 (emoji, kana,
|
|
23
|
+
ideographic characters and combining marks) get their own widths. Other
|
|
24
|
+
text wraps as before.
|
|
25
|
+
- html5ever 0.40.1, still with
|
|
26
|
+
[servo/html5ever#800](https://github.com/servo/html5ever/pull/800).
|
|
27
|
+
Output is unchanged. Building from source needs Rust 1.85 or later.
|
|
28
|
+
|
|
3
29
|
## 0.4.0 (2026-10-22)
|
|
4
30
|
|
|
5
31
|
- `html2text()` is rendered by this package's own code. The library it used
|
|
@@ -10,9 +10,9 @@ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
|
|
10
10
|
|
|
11
11
|
[[package]]
|
|
12
12
|
name = "cc"
|
|
13
|
-
version = "1.
|
|
13
|
+
version = "1.11.3"
|
|
14
14
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
-
checksum = "
|
|
15
|
+
checksum = "02f0e023adb368345ce0ca6cdfc0f24a06554468d0e8503e14a0841de79bfa69"
|
|
16
16
|
dependencies = [
|
|
17
17
|
"find-msvc-tools",
|
|
18
18
|
"shlex",
|
|
@@ -44,10 +44,11 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
|
44
44
|
|
|
45
45
|
[[package]]
|
|
46
46
|
name = "html5ever"
|
|
47
|
-
version = "0.
|
|
47
|
+
version = "0.40.1"
|
|
48
48
|
dependencies = [
|
|
49
49
|
"log",
|
|
50
50
|
"markup5ever",
|
|
51
|
+
"memchr",
|
|
51
52
|
]
|
|
52
53
|
|
|
53
54
|
[[package]]
|
|
@@ -76,15 +77,15 @@ dependencies = [
|
|
|
76
77
|
|
|
77
78
|
[[package]]
|
|
78
79
|
name = "log"
|
|
79
|
-
version = "0.4.
|
|
80
|
+
version = "0.4.35"
|
|
80
81
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
81
|
-
checksum = "
|
|
82
|
+
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
|
82
83
|
|
|
83
84
|
[[package]]
|
|
84
85
|
name = "markup5ever"
|
|
85
|
-
version = "0.
|
|
86
|
+
version = "0.40.0"
|
|
86
87
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
-
checksum = "
|
|
88
|
+
checksum = "0ab3dc68ac4a0f5719e560136778c1ee716e296030d75dbd4484e37e39e3a842"
|
|
88
89
|
dependencies = [
|
|
89
90
|
"log",
|
|
90
91
|
"tendril",
|
|
@@ -143,9 +144,9 @@ dependencies = [
|
|
|
143
144
|
|
|
144
145
|
[[package]]
|
|
145
146
|
name = "phf"
|
|
146
|
-
version = "0.
|
|
147
|
+
version = "0.14.0"
|
|
147
148
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
148
|
-
checksum = "
|
|
149
|
+
checksum = "010378780309880b08997fae13be7834dba947d36393bd372f2b1556deb2a2f6"
|
|
149
150
|
dependencies = [
|
|
150
151
|
"phf_shared",
|
|
151
152
|
"serde",
|
|
@@ -153,9 +154,9 @@ dependencies = [
|
|
|
153
154
|
|
|
154
155
|
[[package]]
|
|
155
156
|
name = "phf_codegen"
|
|
156
|
-
version = "0.
|
|
157
|
+
version = "0.14.0"
|
|
157
158
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
158
|
-
checksum = "
|
|
159
|
+
checksum = "41b585a510fb76fdebead6897982ef2a03a21d8e6cbcca904999742a4afc6ffe"
|
|
159
160
|
dependencies = [
|
|
160
161
|
"phf_generator",
|
|
161
162
|
"phf_shared",
|
|
@@ -163,9 +164,9 @@ dependencies = [
|
|
|
163
164
|
|
|
164
165
|
[[package]]
|
|
165
166
|
name = "phf_generator"
|
|
166
|
-
version = "0.
|
|
167
|
+
version = "0.14.0"
|
|
167
168
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
168
|
-
checksum = "
|
|
169
|
+
checksum = "aeb62e0959d5a1bebc965f4d15d9e2b7cea002b6b0f5ba8cde6cc26738467100"
|
|
169
170
|
dependencies = [
|
|
170
171
|
"fastrand",
|
|
171
172
|
"phf_shared",
|
|
@@ -173,9 +174,9 @@ dependencies = [
|
|
|
173
174
|
|
|
174
175
|
[[package]]
|
|
175
176
|
name = "phf_shared"
|
|
176
|
-
version = "0.
|
|
177
|
+
version = "0.14.0"
|
|
177
178
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
178
|
-
checksum = "
|
|
179
|
+
checksum = "c6fd9027e2d9319be6349febd1db4e8d02aa544921200c9b777720ac34a3aa89"
|
|
179
180
|
dependencies = [
|
|
180
181
|
"siphasher",
|
|
181
182
|
]
|
|
@@ -203,9 +204,9 @@ dependencies = [
|
|
|
203
204
|
|
|
204
205
|
[[package]]
|
|
205
206
|
name = "pulldown-cmark"
|
|
206
|
-
version = "0.13.
|
|
207
|
+
version = "0.13.6"
|
|
207
208
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
208
|
-
checksum = "
|
|
209
|
+
checksum = "3db2be46835f013dd3f4fa7f5f7402c537787b54ebb6fe2b94bbdd7e2669bb7b"
|
|
209
210
|
dependencies = [
|
|
210
211
|
"bitflags",
|
|
211
212
|
"memchr",
|
|
@@ -214,7 +215,7 @@ dependencies = [
|
|
|
214
215
|
|
|
215
216
|
[[package]]
|
|
216
217
|
name = "pyhtml2text"
|
|
217
|
-
version = "0.4.
|
|
218
|
+
version = "0.4.2"
|
|
218
219
|
dependencies = [
|
|
219
220
|
"html5ever",
|
|
220
221
|
"mimalloc",
|
|
@@ -347,15 +348,15 @@ checksum = "33f4fe9184a62d842c9ef383018f3306d8ba224fd9d836f56d7288308847c256"
|
|
|
347
348
|
|
|
348
349
|
[[package]]
|
|
349
350
|
name = "smallvec"
|
|
350
|
-
version = "1.16.
|
|
351
|
+
version = "1.16.6"
|
|
351
352
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
352
|
-
checksum = "
|
|
353
|
+
checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59"
|
|
353
354
|
|
|
354
355
|
[[package]]
|
|
355
356
|
name = "string_cache"
|
|
356
|
-
version = "0.
|
|
357
|
+
version = "0.11.0"
|
|
357
358
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
358
|
-
checksum = "
|
|
359
|
+
checksum = "ffa8a5dbe8b3f0bbe29d4c3225daafaeead63afdc1b65fc4c01a1384166038e6"
|
|
359
360
|
dependencies = [
|
|
360
361
|
"new_debug_unreachable",
|
|
361
362
|
"parking_lot",
|
|
@@ -365,9 +366,9 @@ dependencies = [
|
|
|
365
366
|
|
|
366
367
|
[[package]]
|
|
367
368
|
name = "string_cache_codegen"
|
|
368
|
-
version = "0.
|
|
369
|
+
version = "0.11.2"
|
|
369
370
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
370
|
-
checksum = "
|
|
371
|
+
checksum = "928dcdf75e47626b3617a976ec205d9f057584c371c1f23b782129268d0e6edc"
|
|
371
372
|
dependencies = [
|
|
372
373
|
"phf_generator",
|
|
373
374
|
"phf_shared",
|
|
@@ -377,9 +378,9 @@ dependencies = [
|
|
|
377
378
|
|
|
378
379
|
[[package]]
|
|
379
380
|
name = "syn"
|
|
380
|
-
version = "3.0.
|
|
381
|
+
version = "3.0.10"
|
|
381
382
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
382
|
-
checksum = "
|
|
383
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
383
384
|
dependencies = [
|
|
384
385
|
"proc-macro2",
|
|
385
386
|
"quote",
|
|
@@ -388,9 +389,9 @@ dependencies = [
|
|
|
388
389
|
|
|
389
390
|
[[package]]
|
|
390
391
|
name = "target-lexicon"
|
|
391
|
-
version = "0.13.
|
|
392
|
+
version = "0.13.6"
|
|
392
393
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
393
|
-
checksum = "
|
|
394
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
394
395
|
|
|
395
396
|
[[package]]
|
|
396
397
|
name = "tendril"
|
|
@@ -415,15 +416,15 @@ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
|
415
416
|
|
|
416
417
|
[[package]]
|
|
417
418
|
name = "unicode-width"
|
|
418
|
-
version = "0.2.
|
|
419
|
+
version = "0.2.3"
|
|
419
420
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
420
|
-
checksum = "
|
|
421
|
+
checksum = "ca718471876992059f251e33aafc334346ada08042b7661dd1fe313a9bced557"
|
|
421
422
|
|
|
422
423
|
[[package]]
|
|
423
424
|
name = "web_atoms"
|
|
424
|
-
version = "0.
|
|
425
|
+
version = "0.3.0"
|
|
425
426
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
426
|
-
checksum = "
|
|
427
|
+
checksum = "7572660c8890448ba236b7376f27e389c6a7e1c70195622faced601f855c0ada"
|
|
427
428
|
dependencies = [
|
|
428
429
|
"phf",
|
|
429
430
|
"phf_codegen",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pyhtml2text"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.2"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
license = "MIT"
|
|
6
6
|
publish = false
|
|
@@ -13,9 +13,10 @@ crate-type = ["cdylib"]
|
|
|
13
13
|
[dependencies]
|
|
14
14
|
pyo3 = { version = "0.30", features = ["abi3-py310"] }
|
|
15
15
|
# The HTML parser; patched below.
|
|
16
|
-
html5ever = "0.
|
|
17
|
-
# Display width of characters, for wrapping.
|
|
18
|
-
|
|
16
|
+
html5ever = "0.40"
|
|
17
|
+
# Display width of characters, for wrapping. Pinned, since newer Unicode data
|
|
18
|
+
# can change the output.
|
|
19
|
+
unicode-width = "=0.2.3"
|
|
19
20
|
# Reads the Markdown back to check that emphasis parses as intended.
|
|
20
21
|
pulldown-cmark = { version = "0.13", default-features = false }
|
|
21
22
|
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyhtml2text
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
13
|
+
Classifier: Programming Language :: Python :: Free Threading :: 3 - Stable
|
|
6
14
|
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
15
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
16
|
+
Classifier: Typing :: Typed
|
|
7
17
|
License-File: LICENSE
|
|
8
18
|
Summary: Fast HTML to plain text and Markdown, with relative link resolution
|
|
9
19
|
Keywords: html,text,markdown,html2text
|
|
@@ -33,6 +43,8 @@ html = """<h2>Before you start</h2>
|
|
|
33
43
|
print(html2markdown(html, base_url="https://example.com/docs/intro.html"))
|
|
34
44
|
```
|
|
35
45
|
|
|
46
|
+
Output:
|
|
47
|
+
|
|
36
48
|
```markdown
|
|
37
49
|
## Before you start
|
|
38
50
|
|
|
@@ -115,12 +127,13 @@ To plain text:
|
|
|
115
127
|
| **pyhtml2text** | **7.0 ms** | **1.3 ms** |
|
|
116
128
|
|
|
117
129
|
- The GIL is released while converting, so threads scale across cores. On
|
|
118
|
-
free-threaded Python (3.14t) the module runs without re-enabling
|
|
130
|
+
free-threaded Python (3.14t and 3.15t) the module runs without re-enabling
|
|
131
|
+
the GIL.
|
|
119
132
|
- Wheels for Linux (x86_64, aarch64), macOS and Windows x64 are built with
|
|
120
133
|
profile-guided optimisation, which makes them about 25% faster. Other
|
|
121
134
|
platforms get the same code without it.
|
|
122
135
|
- Deeply nested HTML is parsed in linear time, so hostile input can't stall a
|
|
123
|
-
worker: 40,000 nested lists take 0.
|
|
136
|
+
worker: 40,000 nested lists take 0.02 s, against 18 s with stock html5ever,
|
|
124
137
|
and 100,000 levels of nesting followed by unmatched end tags take under
|
|
125
138
|
0.1 s.
|
|
126
139
|
|
|
@@ -18,6 +18,8 @@ html = """<h2>Before you start</h2>
|
|
|
18
18
|
print(html2markdown(html, base_url="https://example.com/docs/intro.html"))
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
Output:
|
|
22
|
+
|
|
21
23
|
```markdown
|
|
22
24
|
## Before you start
|
|
23
25
|
|
|
@@ -100,12 +102,13 @@ To plain text:
|
|
|
100
102
|
| **pyhtml2text** | **7.0 ms** | **1.3 ms** |
|
|
101
103
|
|
|
102
104
|
- The GIL is released while converting, so threads scale across cores. On
|
|
103
|
-
free-threaded Python (3.14t) the module runs without re-enabling
|
|
105
|
+
free-threaded Python (3.14t and 3.15t) the module runs without re-enabling
|
|
106
|
+
the GIL.
|
|
104
107
|
- Wheels for Linux (x86_64, aarch64), macOS and Windows x64 are built with
|
|
105
108
|
profile-guided optimisation, which makes them about 25% faster. Other
|
|
106
109
|
platforms get the same code without it.
|
|
107
110
|
- Deeply nested HTML is parsed in linear time, so hostile input can't stall a
|
|
108
|
-
worker: 40,000 nested lists take 0.
|
|
111
|
+
worker: 40,000 nested lists take 0.02 s, against 18 s with stock html5ever,
|
|
109
112
|
and 100,000 levels of nesting followed by unmatched end tags take under
|
|
110
113
|
0.1 s.
|
|
111
114
|
|
|
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pyhtml2text"
|
|
7
|
-
version = "0.4.
|
|
7
|
+
version = "0.4.2"
|
|
8
8
|
description = "Fast HTML to plain text and Markdown, with relative link resolution"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -15,7 +15,17 @@ keywords = ["html", "text", "markdown", "html2text"]
|
|
|
15
15
|
classifiers = [
|
|
16
16
|
"Programming Language :: Rust",
|
|
17
17
|
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Programming Language :: Python :: 3.15",
|
|
25
|
+
"Programming Language :: Python :: Free Threading :: 3 - Stable",
|
|
18
26
|
"Topic :: Text Processing :: Markup :: HTML",
|
|
27
|
+
"Topic :: Text Processing :: Markup :: Markdown",
|
|
28
|
+
"Typing :: Typed",
|
|
19
29
|
]
|
|
20
30
|
|
|
21
31
|
[project.urls]
|
|
@@ -756,11 +756,7 @@ fn layout(r: &mut Renderer, cells: &mut [Cell], nrows_all: usize, width: usize)
|
|
|
756
756
|
fn vertical(cells: &[Cell], nrows: usize, width: usize, borders: bool) -> Job {
|
|
757
757
|
let mut pieces = Vec::new();
|
|
758
758
|
let mut to_render = Vec::new();
|
|
759
|
-
let rule = || Line
|
|
760
|
-
text: "─".repeat(width),
|
|
761
|
-
width,
|
|
762
|
-
kind: LineKind::Rule,
|
|
763
|
-
};
|
|
759
|
+
let rule = || Line::of_kind("─".repeat(width), width, LineKind::Rule);
|
|
764
760
|
let sep = || Line::new("/".repeat(width), width);
|
|
765
761
|
if borders {
|
|
766
762
|
pieces.push(Some(rule()));
|
|
@@ -1020,15 +1016,12 @@ impl Grid {
|
|
|
1020
1016
|
}
|
|
1021
1017
|
|
|
1022
1018
|
fn row_line(&self, row: usize, line: usize, sep: &str) -> Line {
|
|
1023
|
-
let
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
LineKind::Text
|
|
1028
|
-
} else {
|
|
1029
|
-
LineKind::Row
|
|
1030
|
-
},
|
|
1019
|
+
let kind = if sep == " " {
|
|
1020
|
+
LineKind::Text
|
|
1021
|
+
} else {
|
|
1022
|
+
LineKind::Row
|
|
1031
1023
|
};
|
|
1024
|
+
let mut out = Line::of_kind(String::new(), 0, kind);
|
|
1032
1025
|
for (i, &(idx, _, _)) in self.vis[row].iter().enumerate() {
|
|
1033
1026
|
if i > 0 {
|
|
1034
1027
|
out.text.push_str(sep);
|
|
@@ -1134,11 +1127,7 @@ impl Grid {
|
|
|
1134
1127
|
}
|
|
1135
1128
|
}
|
|
1136
1129
|
// Lay the spanning cells' text over the line.
|
|
1137
|
-
let mut out = Line
|
|
1138
|
-
text: String::new(),
|
|
1139
|
-
width: 0,
|
|
1140
|
-
kind: LineKind::Rule,
|
|
1141
|
-
};
|
|
1130
|
+
let mut out = Line::of_kind(String::new(), 0, LineKind::Rule);
|
|
1142
1131
|
texts.sort_by_key(|t| t.0);
|
|
1143
1132
|
let mut ti = texts.into_iter().peekable();
|
|
1144
1133
|
let mut x = 0;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
//! pending and only carried out when something is written after them, so
|
|
8
8
|
//! empty blocks leave no trace and adjacent requests merge.
|
|
9
9
|
|
|
10
|
+
use std::collections::HashMap;
|
|
10
11
|
use std::mem;
|
|
11
12
|
|
|
12
13
|
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
|
|
@@ -85,7 +86,11 @@ pub fn render(dom: &Dom, opts: &Options) -> Result<String, String> {
|
|
|
85
86
|
parent.r.footnotes = mem::take(&mut done.r.footnotes);
|
|
86
87
|
parent.r.table_sizes = mem::take(&mut done.r.table_sizes);
|
|
87
88
|
let lines = done.r.bufs.pop().unwrap().finish();
|
|
88
|
-
parent
|
|
89
|
+
parent
|
|
90
|
+
.table
|
|
91
|
+
.as_mut()
|
|
92
|
+
.unwrap()
|
|
93
|
+
.add(lines.into_iter().map(Line::flatten).collect());
|
|
89
94
|
}
|
|
90
95
|
Ok(levels.pop().unwrap().r.finish())
|
|
91
96
|
}
|
|
@@ -113,6 +118,10 @@ pub struct Line {
|
|
|
113
118
|
pub text: String,
|
|
114
119
|
pub width: usize,
|
|
115
120
|
pub kind: LineKind,
|
|
121
|
+
/// The prefixes of the blocks the line is in, still to be put in front
|
|
122
|
+
/// of `text`, written back to front: each block then adds its own in
|
|
123
|
+
/// time for its length, however deeply blocks are nested.
|
|
124
|
+
rprefix: String,
|
|
116
125
|
}
|
|
117
126
|
|
|
118
127
|
/// What a line is, for a table it ends up in.
|
|
@@ -127,16 +136,40 @@ pub enum LineKind {
|
|
|
127
136
|
|
|
128
137
|
impl Line {
|
|
129
138
|
pub fn new(text: String, width: usize) -> Line {
|
|
139
|
+
Line::of_kind(text, width, LineKind::Text)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
pub fn of_kind(text: String, width: usize, kind: LineKind) -> Line {
|
|
130
143
|
Line {
|
|
131
144
|
text,
|
|
132
145
|
width,
|
|
133
|
-
kind
|
|
146
|
+
kind,
|
|
147
|
+
rprefix: String::new(),
|
|
134
148
|
}
|
|
135
149
|
}
|
|
136
150
|
|
|
137
151
|
fn empty() -> Line {
|
|
138
152
|
Line::new(String::new(), 0)
|
|
139
153
|
}
|
|
154
|
+
|
|
155
|
+
fn add_prefix(&mut self, prefix: &str) {
|
|
156
|
+
self.rprefix.extend(prefix.chars().rev());
|
|
157
|
+
self.width += prefix.len();
|
|
158
|
+
// A prefix makes a table's lines plain text.
|
|
159
|
+
self.kind = LineKind::Text;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// The line with its prefixes in front of it.
|
|
163
|
+
fn flatten(mut self) -> Line {
|
|
164
|
+
if !self.rprefix.is_empty() {
|
|
165
|
+
let mut text = String::with_capacity(self.rprefix.len() + self.text.len());
|
|
166
|
+
text.extend(self.rprefix.chars().rev());
|
|
167
|
+
text.push_str(&self.text);
|
|
168
|
+
self.text = text;
|
|
169
|
+
self.rprefix.clear();
|
|
170
|
+
}
|
|
171
|
+
self
|
|
172
|
+
}
|
|
140
173
|
}
|
|
141
174
|
|
|
142
175
|
/// One buffer of output lines.
|
|
@@ -150,7 +183,7 @@ struct Buf {
|
|
|
150
183
|
word: String,
|
|
151
184
|
word_w: usize,
|
|
152
185
|
pieces: Vec<usize>,
|
|
153
|
-
word_style:
|
|
186
|
+
word_style: u32,
|
|
154
187
|
/// The word has a character of non-zero width.
|
|
155
188
|
word_base: bool,
|
|
156
189
|
/// A space is due before the next word.
|
|
@@ -188,7 +221,7 @@ impl Buf {
|
|
|
188
221
|
word: String::new(),
|
|
189
222
|
word_w: 0,
|
|
190
223
|
pieces: Vec::new(),
|
|
191
|
-
word_style:
|
|
224
|
+
word_style: 0,
|
|
192
225
|
word_base: false,
|
|
193
226
|
space: false,
|
|
194
227
|
open: false,
|
|
@@ -410,8 +443,11 @@ pub struct Renderer<'a> {
|
|
|
410
443
|
/// Sizes of the tables seen so far, shared with the cells' renderers.
|
|
411
444
|
pub table_sizes: table::Sizes,
|
|
412
445
|
/// The styled elements (emphasis, code, links...) the text is inside.
|
|
413
|
-
/// Text in one style is measured as one piece.
|
|
414
|
-
|
|
446
|
+
/// Text in one style is measured as one piece. Each distinct stack of
|
|
447
|
+
/// them is numbered (`styles`, 0 for none), and this holds the number of
|
|
448
|
+
/// the stack up to each of them.
|
|
449
|
+
style: Vec<u32>,
|
|
450
|
+
styles: HashMap<(u32, u8), u32>,
|
|
415
451
|
/// Width of the leading whitespace of a `<pre>` line, or of whitespace
|
|
416
452
|
/// after a tab, held until something follows it.
|
|
417
453
|
prews: usize,
|
|
@@ -427,6 +463,7 @@ impl<'a> Renderer<'a> {
|
|
|
427
463
|
footnotes: Vec::new(),
|
|
428
464
|
table_sizes: table::Sizes::new(),
|
|
429
465
|
style: Vec::new(),
|
|
466
|
+
styles: HashMap::new(),
|
|
430
467
|
prews: 0,
|
|
431
468
|
after_tab: false,
|
|
432
469
|
}
|
|
@@ -437,11 +474,26 @@ impl<'a> Renderer<'a> {
|
|
|
437
474
|
}
|
|
438
475
|
|
|
439
476
|
fn mark(&mut self) {
|
|
440
|
-
|
|
477
|
+
// Frames are marked from the outermost in, so once one is found
|
|
478
|
+
// marked, so are all those outside it.
|
|
479
|
+
for f in self.frames.iter_mut().rev() {
|
|
480
|
+
if f.wrote {
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
441
483
|
f.wrote = true;
|
|
442
484
|
}
|
|
443
485
|
}
|
|
444
486
|
|
|
487
|
+
fn push_style(&mut self, id: u8) {
|
|
488
|
+
let next = self.styles.len() as u32 + 1;
|
|
489
|
+
let style = *self.styles.entry((self.cur_style(), id)).or_insert(next);
|
|
490
|
+
self.style.push(style);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
fn cur_style(&self) -> u32 {
|
|
494
|
+
self.style.last().copied().unwrap_or(0)
|
|
495
|
+
}
|
|
496
|
+
|
|
445
497
|
/// The first thing happens in a buffer: carry out the separator before
|
|
446
498
|
/// its block, in the parent (and so on up).
|
|
447
499
|
fn wake(&mut self) {
|
|
@@ -558,10 +610,11 @@ impl<'a> Renderer<'a> {
|
|
|
558
610
|
|
|
559
611
|
fn word_char(&mut self, c: char) {
|
|
560
612
|
let w = char_width(c);
|
|
613
|
+
let style = self.cur_style();
|
|
561
614
|
let b = self.bufs.last_mut().unwrap();
|
|
562
|
-
if b.word_style !=
|
|
615
|
+
if b.word_style != style {
|
|
563
616
|
b.piece();
|
|
564
|
-
b.word_style
|
|
617
|
+
b.word_style = style;
|
|
565
618
|
}
|
|
566
619
|
b.word.push(c);
|
|
567
620
|
b.word_w += w;
|
|
@@ -599,6 +652,7 @@ impl<'a> Renderer<'a> {
|
|
|
599
652
|
self.touch();
|
|
600
653
|
}
|
|
601
654
|
}
|
|
655
|
+
let style = self.cur_style();
|
|
602
656
|
for c in seg.chars() {
|
|
603
657
|
let b = self.bufs.last_mut().unwrap();
|
|
604
658
|
let at_start = (b.cur.is_empty() || self.after_tab) && b.word.is_empty();
|
|
@@ -641,9 +695,9 @@ impl<'a> Renderer<'a> {
|
|
|
641
695
|
}
|
|
642
696
|
b.chop(&" ".repeat(n));
|
|
643
697
|
}
|
|
644
|
-
if b.word_style !=
|
|
698
|
+
if b.word_style != style {
|
|
645
699
|
b.piece();
|
|
646
|
-
b.word_style
|
|
700
|
+
b.word_style = style;
|
|
647
701
|
}
|
|
648
702
|
b.word.push(c);
|
|
649
703
|
b.word_w += char_width(c);
|
|
@@ -731,22 +785,12 @@ impl<'a> Renderer<'a> {
|
|
|
731
785
|
let lines = self.bufs.pop().unwrap().finish();
|
|
732
786
|
if !lines.is_empty() {
|
|
733
787
|
let b = self.b();
|
|
734
|
-
for (i, line) in lines.into_iter().enumerate() {
|
|
788
|
+
for (i, mut line) in lines.into_iter().enumerate() {
|
|
735
789
|
let prefix = if i == 0 { first } else { rest };
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
let kind = if prefix.is_empty() {
|
|
741
|
-
line.kind
|
|
742
|
-
} else {
|
|
743
|
-
LineKind::Text
|
|
744
|
-
};
|
|
745
|
-
b.lines.push(Line {
|
|
746
|
-
text: s,
|
|
747
|
-
width: prefix.len() + line.width,
|
|
748
|
-
kind,
|
|
749
|
-
});
|
|
790
|
+
if !prefix.is_empty() {
|
|
791
|
+
line.add_prefix(prefix);
|
|
792
|
+
}
|
|
793
|
+
b.lines.push(line);
|
|
750
794
|
}
|
|
751
795
|
b.blank_after = false;
|
|
752
796
|
b.content = true;
|
|
@@ -833,7 +877,7 @@ impl<'a> Renderer<'a> {
|
|
|
833
877
|
self.start(Kind::Lead(LINE));
|
|
834
878
|
stack.push(Step::Leave(Leave::Frame));
|
|
835
879
|
// Unlike emphasis, the markers are part of the term's style.
|
|
836
|
-
self.
|
|
880
|
+
self.push_style(b'd');
|
|
837
881
|
stack.push(Step::Leave(Leave::Styled("")));
|
|
838
882
|
if self.opts.decorate {
|
|
839
883
|
self.text("*");
|
|
@@ -938,7 +982,7 @@ impl<'a> Renderer<'a> {
|
|
|
938
982
|
"code" => {
|
|
939
983
|
// Unlike emphasis, the markers are part of the code's
|
|
940
984
|
// style.
|
|
941
|
-
self.
|
|
985
|
+
self.push_style(b'c');
|
|
942
986
|
if decorate {
|
|
943
987
|
self.text("`");
|
|
944
988
|
stack.push(Step::Leave(Leave::Styled("")));
|
|
@@ -953,7 +997,7 @@ impl<'a> Renderer<'a> {
|
|
|
953
997
|
"ins" => ("", "", b'n'),
|
|
954
998
|
_ if sup_digits(node).is_some() => {
|
|
955
999
|
let digits = sup_digits(node).unwrap();
|
|
956
|
-
self.
|
|
1000
|
+
self.push_style(b's');
|
|
957
1001
|
self.text(&digits);
|
|
958
1002
|
self.style.pop();
|
|
959
1003
|
return;
|
|
@@ -963,12 +1007,12 @@ impl<'a> Renderer<'a> {
|
|
|
963
1007
|
if !open.is_empty() {
|
|
964
1008
|
self.text(open);
|
|
965
1009
|
}
|
|
966
|
-
self.
|
|
1010
|
+
self.push_style(id);
|
|
967
1011
|
Leave::Styled(close)
|
|
968
1012
|
}
|
|
969
1013
|
"del" | "s" => {
|
|
970
1014
|
self.b().strike += 1;
|
|
971
|
-
self.
|
|
1015
|
+
self.push_style(b'x');
|
|
972
1016
|
Leave::Strike
|
|
973
1017
|
}
|
|
974
1018
|
"a" => match attr("href") {
|
|
@@ -982,7 +1026,7 @@ impl<'a> Renderer<'a> {
|
|
|
982
1026
|
None => href,
|
|
983
1027
|
};
|
|
984
1028
|
self.text("[");
|
|
985
|
-
self.
|
|
1029
|
+
self.push_style(b'a');
|
|
986
1030
|
Leave::Link(url)
|
|
987
1031
|
}
|
|
988
1032
|
None => Leave::Nothing,
|
|
@@ -1179,6 +1223,7 @@ impl<'a> Renderer<'a> {
|
|
|
1179
1223
|
let lines = b.finish();
|
|
1180
1224
|
let mut out = String::new();
|
|
1181
1225
|
for line in lines {
|
|
1226
|
+
out.extend(line.rprefix.chars().rev());
|
|
1182
1227
|
out.push_str(&line.text);
|
|
1183
1228
|
out.push('\n');
|
|
1184
1229
|
}
|