pyhtml2text 0.4.1__cp315-cp315t-win_arm64.whl

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.
@@ -0,0 +1,3 @@
1
+ from ._pyhtml2text import html2markdown, html2text
2
+
3
+ __all__ = ["html2markdown", "html2text"]
@@ -0,0 +1,13 @@
1
+ def html2text(
2
+ html: str | bytes,
3
+ width: int = 80,
4
+ *,
5
+ base_url: str | None = None,
6
+ decorate: bool = True,
7
+ link_footnotes: bool = True,
8
+ table_borders: bool = True,
9
+ wrap_links: bool = True,
10
+ max_wrap_width: int | None = None,
11
+ raw: bool = False,
12
+ ) -> str: ...
13
+ def html2markdown(html: str | bytes, *, base_url: str | None = None) -> str: ...
pyhtml2text/py.typed ADDED
File without changes
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyhtml2text
3
+ Version: 0.4.1
4
+ Classifier: Programming Language :: Rust
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
14
+ Classifier: Topic :: Text Processing :: Markup :: HTML
15
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
16
+ Classifier: Typing :: Typed
17
+ License-File: LICENSE
18
+ Summary: Fast HTML to plain text and Markdown, with relative link resolution
19
+ Keywords: html,text,markdown,html2text
20
+ Author-email: Jared Lynskey <jared@lynskey.co.nz>
21
+ License-Expression: MIT
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
24
+ Project-URL: Source, https://github.com/jaredlynskey/pyhtml2text
25
+
26
+ # pyhtml2text
27
+
28
+ Fast HTML to plain text and to Markdown for Python, written in Rust.
29
+
30
+ Relative links can be resolved against the page's URL, so the output's links
31
+ work on their own.
32
+
33
+ ## Markdown
34
+
35
+ ```python
36
+ from pyhtml2text import html2markdown
37
+
38
+ html = """<h2>Before you start</h2>
39
+ <p>Read the <a href="setup.html">setup guide</a> and <b>back up</b> your data.</p>
40
+ <img src="/img/diagram.png" alt="How it fits together">
41
+ <table><tr><th>Plan</th><th>Price</th></tr><tr><td>Basic</td><td>Free</td></tr></table>"""
42
+
43
+ print(html2markdown(html, base_url="https://example.com/docs/intro.html"))
44
+ ```
45
+
46
+ Output:
47
+
48
+ ```markdown
49
+ ## Before you start
50
+
51
+ Read the [setup guide](https://example.com/docs/setup.html) and **back up** your data.
52
+
53
+ ![How it fits together](https://example.com/img/diagram.png)
54
+
55
+ | Plan | Price |
56
+ | --- | --- |
57
+ | Basic | Free |
58
+ ```
59
+
60
+ `html2markdown(html, *, base_url=None)` writes
61
+ [CommonMark](https://commonmark.org/) with GitHub's tables and
62
+ strikethrough, in the usual conventions:
63
+
64
+ - `#` headings, `-` bullets, `_emphasis_` and `**strong**`, `~~strikethrough~~`.
65
+ - Inline links and images, `[text](url)` and `![alt](src)`, made absolute when
66
+ `base_url` is given. A link whose only content is an icon uses its
67
+ `aria-label` or `title` as its text.
68
+ - Fenced code blocks, tagged with the language when the page names one
69
+ (`class="language-python"`).
70
+ - Pipe tables. Cells spanning rows or columns become empty cells, a table
71
+ without a header row gets an empty one, and tables used for page layout are
72
+ written as plain paragraphs.
73
+ - Characters are escaped only where Markdown would otherwise read them as
74
+ syntax, so `snake_case`, `5 * 3` and `$5` stay as they are.
75
+ - Lines aren't wrapped. Hidden content (`hidden`, `aria-hidden`,
76
+ `display: none`), scripts, styles and form controls are left out.
77
+
78
+ The output is checked by rendering it back with a CommonMark parser and
79
+ comparing every word, link and image with the original page, on real sites
80
+ and on tens of thousands of random documents (`tests/markdown_check.py`).
81
+
82
+ ## Plain text
83
+
84
+ ```python
85
+ from pyhtml2text import html2text
86
+
87
+ html = '<p>Please <a href="/login">sign in</a> first.</p>'
88
+
89
+ print(html2text(html, base_url="https://example.com/docs/page.html"))
90
+ # Please [sign in][1] first.
91
+ #
92
+ # [1]: https://example.com/login
93
+ ```
94
+
95
+ `html2text(html, width=80, *, ...)`
96
+
97
+ | option | default | |
98
+ |---|---|---|
99
+ | `base_url` | `None` | resolve relative `href`s against this URL (RFC 3986). Absolute and `mailto:` etc. links are left alone |
100
+ | `decorate` | `True` | markdown-ish `*em*`, `**strong**`, `` `code` `` |
101
+ | `link_footnotes` | `True` | list link targets as `[1]: ...` footnotes |
102
+ | `table_borders` | `True` | draw table borders |
103
+ | `wrap_links` | `True` | allow long links to wrap |
104
+ | `max_wrap_width` | `None` | wrap paragraphs narrower than `width` |
105
+ | `raw` | `False` | flatten tables so cell text stays together |
106
+
107
+ Both functions take a `str` or UTF-8 `bytes` (e.g. `response.content`).
108
+ Requires Python 3.10 or later.
109
+
110
+ ## Performance
111
+
112
+ Median time on an Apple Silicon Mac. To Markdown:
113
+
114
+ | | Wikipedia article (1 MB) | BBC News front page (370 KB) | Python docs page (245 KB) |
115
+ |---|---|---|---|
116
+ | [markdownify](https://pypi.org/project/markdownify/) | 184 ms | 28 ms | 97 ms |
117
+ | [html2text](https://pypi.org/project/html2text/) (pure Python) | 73 ms | 13 ms | 37 ms |
118
+ | [html-to-markdown](https://pypi.org/project/html-to-markdown/) | 44 ms | 5.6 ms | 15 ms |
119
+ | **pyhtml2text** | **14 ms** | **1.7 ms** | **4.5 ms** |
120
+
121
+ To plain text:
122
+
123
+ | | Wikipedia article (780 KB) | BBC News front page (370 KB) |
124
+ |---|---|---|
125
+ | [html2text](https://pypi.org/project/html2text/) (pure Python) | 71.5 ms | 14.9 ms |
126
+ | [html2text-rs](https://pypi.org/project/html2text-rs/) | 15.2 ms | 2.5 ms |
127
+ | **pyhtml2text** | **7.0 ms** | **1.3 ms** |
128
+
129
+ - The GIL is released while converting, so threads scale across cores. On
130
+ free-threaded Python (3.14t and 3.15t) the module runs without re-enabling
131
+ the GIL.
132
+ - Wheels for Linux (x86_64, aarch64), macOS and Windows x64 are built with
133
+ profile-guided optimisation, which makes them about 25% faster. Other
134
+ platforms get the same code without it.
135
+ - Deeply nested HTML is parsed in linear time, so hostile input can't stall a
136
+ worker: 40,000 nested lists take 0.02 s, against 18 s with stock html5ever,
137
+ and 100,000 levels of nesting followed by unmatched end tags take under
138
+ 0.1 s.
139
+
140
+ ## Credits
141
+
142
+ HTML is parsed by a copy of [html5ever](https://github.com/servo/html5ever)
143
+ (MIT/Apache-2.0) with
144
+ [servo/html5ever#800](https://github.com/servo/html5ever/pull/800) by Josef
145
+ Guenther applied, which makes parsing deeply nested HTML linear (see
146
+ `vendor/`). Text is measured with
147
+ [unicode-width](https://github.com/unicode-rs/unicode-width) (MIT/Apache-2.0)
148
+ and Markdown output is checked with
149
+ [pulldown-cmark](https://github.com/raphlinus/pulldown-cmark) (MIT). This
150
+ package isn't affiliated with or endorsed by any of these projects, so please
151
+ report issues here rather than upstream.
152
+
@@ -0,0 +1,9 @@
1
+ pyhtml2text/__init__.py,sha256=24rkdbERHDtRelaQ1pDmaS1cTgd9n87s0nUaXVSdtc4,96
2
+ pyhtml2text/__init__.pyi,sha256=TtJHtioY5OQpscbFf5pWTTcyGpiKWrynoiCs0ZkUEp4,390
3
+ pyhtml2text/_pyhtml2text.cp315t-win_arm64.pyd,sha256=MSKNW97r7F45gkr_Mpi1VZd5UDI8AdLJ6VGTFcLnGXA,1528320
4
+ pyhtml2text/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pyhtml2text-0.4.1.dist-info/METADATA,sha256=9giJWDPNhJbQmKLrzWR9mvIH_PTEM5_cTnOkyLiOGuM,6198
6
+ pyhtml2text-0.4.1.dist-info/WHEEL,sha256=Wetpyc8lcujDpDJCCb0xpLwNfTI9y3lFuE9yQx58cOM,98
7
+ pyhtml2text-0.4.1.dist-info/licenses/LICENSE,sha256=ST5LZ1plHRGeFqjXcM-98MHkWEZ_OiG8PBaY57GPe6c,1092
8
+ pyhtml2text-0.4.1.dist-info/sboms/pyhtml2text.cyclonedx.json,sha256=42EHh2kMvQZFfgp64RB6oC8tqTTpSXb7H_cfTQQBIq8,53538
9
+ pyhtml2text-0.4.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.16.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp315-cp315t-win_arm64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jared Lynskey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.