html-to-markdown 1.2.0__py3-none-any.whl → 1.2.1__py3-none-any.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.
Potentially problematic release.
This version of html-to-markdown might be problematic. Click here for more details.
- html_to_markdown/__init__.py +2 -2
- html_to_markdown/converters.py +4 -9
- html_to_markdown/processing.py +3 -6
- html_to_markdown-1.2.1.dist-info/METADATA +220 -0
- html_to_markdown-1.2.1.dist-info/RECORD +12 -0
- {html_to_markdown-1.2.0.dist-info → html_to_markdown-1.2.1.dist-info}/licenses/LICENSE +1 -1
- html_to_markdown/legacy.py +0 -89
- html_to_markdown-1.2.0.dist-info/METADATA +0 -102
- html_to_markdown-1.2.0.dist-info/RECORD +0 -13
- {html_to_markdown-1.2.0.dist-info → html_to_markdown-1.2.1.dist-info}/WHEEL +0 -0
html_to_markdown/__init__.py
CHANGED
html_to_markdown/converters.py
CHANGED
|
@@ -85,7 +85,7 @@ def _create_inline_converter(markup_prefix: str) -> Callable[[Tag, str], str]:
|
|
|
85
85
|
|
|
86
86
|
return f"{prefix}{markup_prefix}{text}{markup_suffix}{suffix}"
|
|
87
87
|
|
|
88
|
-
return cast(Callable[[Tag, str], str], implementation)
|
|
88
|
+
return cast("Callable[[Tag, str], str]", implementation)
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
def _get_colspan(tag: Tag) -> int:
|
|
@@ -187,7 +187,7 @@ def _convert_li(*, tag: Tag, text: str, bullets: str) -> str:
|
|
|
187
187
|
parent = tag.parent
|
|
188
188
|
if parent is not None and parent.name == "ol":
|
|
189
189
|
start = (
|
|
190
|
-
int(cast(str, parent["start"]))
|
|
190
|
+
int(cast("str", parent["start"]))
|
|
191
191
|
if isinstance(parent.get("start"), str) and str(parent.get("start")).isnumeric()
|
|
192
192
|
else 1
|
|
193
193
|
)
|
|
@@ -263,7 +263,6 @@ def _convert_tr(*, tag: Tag, text: str) -> str:
|
|
|
263
263
|
overline = ""
|
|
264
264
|
underline = ""
|
|
265
265
|
if is_headrow and not tag.previous_sibling:
|
|
266
|
-
# first row and is headline: print headline underline
|
|
267
266
|
full_colspan = 0
|
|
268
267
|
for cell in cells:
|
|
269
268
|
if "colspan" in cell.attrs and cell["colspan"].isdigit():
|
|
@@ -272,12 +271,8 @@ def _convert_tr(*, tag: Tag, text: str) -> str:
|
|
|
272
271
|
full_colspan += 1
|
|
273
272
|
underline += "| " + " | ".join(["---"] * full_colspan) + " |" + "\n"
|
|
274
273
|
elif not tag.previous_sibling and (
|
|
275
|
-
parent_name == "table" or (parent_name == "tbody" and not cast(Tag, tag.parent).previous_sibling)
|
|
274
|
+
parent_name == "table" or (parent_name == "tbody" and not cast("Tag", tag.parent).previous_sibling)
|
|
276
275
|
):
|
|
277
|
-
# first row, not headline, and:
|
|
278
|
-
# - the parent is table or
|
|
279
|
-
# - the parent is tbody at the beginning of a table.
|
|
280
|
-
# print empty headline above this row
|
|
281
276
|
overline += "| " + " | ".join([""] * len(cells)) + " |" + "\n"
|
|
282
277
|
overline += "| " + " | ".join(["---"] * len(cells)) + " |" + "\n"
|
|
283
278
|
return overline + "|" + text + "\n" + underline
|
|
@@ -334,7 +329,7 @@ def create_converters_map(
|
|
|
334
329
|
return func(**kwargs)
|
|
335
330
|
return func(text)
|
|
336
331
|
|
|
337
|
-
return cast(Callable[[str, Tag], T], _inner)
|
|
332
|
+
return cast("Callable[[str, Tag], T]", _inner)
|
|
338
333
|
|
|
339
334
|
return {
|
|
340
335
|
"a": _wrapper(partial(_convert_a, autolinks=autolinks, default_title=default_title)),
|
html_to_markdown/processing.py
CHANGED
|
@@ -87,7 +87,9 @@ def _process_tag(
|
|
|
87
87
|
strip: set[str] | None,
|
|
88
88
|
) -> str:
|
|
89
89
|
should_convert_tag = _should_convert_tag(tag_name=tag.name, strip=strip, convert=convert)
|
|
90
|
-
tag_name: SupportedTag | None =
|
|
90
|
+
tag_name: SupportedTag | None = (
|
|
91
|
+
cast("SupportedTag", tag.name.lower()) if tag.name.lower() in converters_map else None
|
|
92
|
+
)
|
|
91
93
|
text = ""
|
|
92
94
|
|
|
93
95
|
is_heading = html_heading_re.match(tag.name) is not None
|
|
@@ -142,11 +144,9 @@ def _process_text(
|
|
|
142
144
|
) -> str:
|
|
143
145
|
text = str(el) or ""
|
|
144
146
|
|
|
145
|
-
# normalize whitespace if we're not inside a preformatted element
|
|
146
147
|
if not el.find_parent("pre"):
|
|
147
148
|
text = whitespace_re.sub(" ", text)
|
|
148
149
|
|
|
149
|
-
# escape special characters if we're not inside a preformatted or code element
|
|
150
150
|
if not el.find_parent(["pre", "code", "kbd", "samp"]):
|
|
151
151
|
text = escape(
|
|
152
152
|
text=text,
|
|
@@ -155,9 +155,6 @@ def _process_text(
|
|
|
155
155
|
escape_underscores=escape_underscores,
|
|
156
156
|
)
|
|
157
157
|
|
|
158
|
-
# remove trailing whitespaces if any of the following condition is true:
|
|
159
|
-
# - current text node is the last node in li
|
|
160
|
-
# - current text node is followed by an embedded list
|
|
161
158
|
if (
|
|
162
159
|
el.parent
|
|
163
160
|
and el.parent.name == "li"
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: html-to-markdown
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Convert HTML to markdown
|
|
5
|
+
Project-URL: homepage, https://github.com/Goldziher/html-to-markdown
|
|
6
|
+
Author-email: Na'aman Hirschfeld <nhirschfeld@gmail.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: converter,html,markdown,text-extraction,text-processing
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Text Processing
|
|
20
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
21
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
22
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Requires-Dist: beautifulsoup4>=4.12.3
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# html-to-markdown
|
|
30
|
+
|
|
31
|
+
A modern, fully typed Python library for converting HTML to Markdown. This library is a completely rewritten fork
|
|
32
|
+
of [markdownify](https://pypi.org/project/markdownify/) with a modernized codebase, strict type safety and support for
|
|
33
|
+
Python 3.9+.
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- Full type safety with strict MyPy adherence
|
|
38
|
+
- Functional API design
|
|
39
|
+
- Extensive test coverage
|
|
40
|
+
- Configurable conversion options
|
|
41
|
+
- CLI tool for easy conversions
|
|
42
|
+
- Support for pre-configured BeautifulSoup instances
|
|
43
|
+
- Strict semver versioning
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
pip install html-to-markdown
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
Convert HTML to Markdown with a single function call:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from html_to_markdown import convert_to_markdown
|
|
57
|
+
|
|
58
|
+
html = """
|
|
59
|
+
<article>
|
|
60
|
+
<h1>Welcome</h1>
|
|
61
|
+
<p>This is a <strong>sample</strong> with a <a href="https://example.com">link</a>.</p>
|
|
62
|
+
<ul>
|
|
63
|
+
<li>Item 1</li>
|
|
64
|
+
<li>Item 2</li>
|
|
65
|
+
</ul>
|
|
66
|
+
</article>
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
markdown = convert_to_markdown(html)
|
|
70
|
+
print(markdown)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Output:
|
|
74
|
+
|
|
75
|
+
```markdown
|
|
76
|
+
# Welcome
|
|
77
|
+
|
|
78
|
+
This is a **sample** with a [link](https://example.com).
|
|
79
|
+
|
|
80
|
+
* Item 1
|
|
81
|
+
* Item 2
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Working with BeautifulSoup
|
|
85
|
+
|
|
86
|
+
If you need more control over HTML parsing, you can pass a pre-configured BeautifulSoup instance:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from bs4 import BeautifulSoup
|
|
90
|
+
from html_to_markdown import convert_to_markdown
|
|
91
|
+
|
|
92
|
+
# Configure BeautifulSoup with your preferred parser
|
|
93
|
+
soup = BeautifulSoup(html, "lxml") # Note: lxml requires additional installation
|
|
94
|
+
markdown = convert_to_markdown(soup)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Advanced Usage
|
|
98
|
+
|
|
99
|
+
### Customizing Conversion Options
|
|
100
|
+
|
|
101
|
+
The library offers extensive customization through various options:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from html_to_markdown import convert_to_markdown
|
|
105
|
+
|
|
106
|
+
html = "<div>Your content here...</div>"
|
|
107
|
+
markdown = convert_to_markdown(
|
|
108
|
+
html,
|
|
109
|
+
heading_style="atx", # Use # style headers
|
|
110
|
+
strong_em_symbol="*", # Use * for bold/italic
|
|
111
|
+
bullets="*+-", # Define bullet point characters
|
|
112
|
+
wrap=True, # Enable text wrapping
|
|
113
|
+
wrap_width=100, # Set wrap width
|
|
114
|
+
escape_asterisks=True, # Escape * characters
|
|
115
|
+
code_language="python", # Default code block language
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Configuration Options
|
|
120
|
+
|
|
121
|
+
| Option | Type | Default | Description |
|
|
122
|
+
| -------------------- | ---- | -------------- | ------------------------------------------------------ |
|
|
123
|
+
| `autolinks` | bool | `True` | Auto-convert URLs to Markdown links |
|
|
124
|
+
| `bullets` | str | `'*+-'` | Characters to use for bullet points |
|
|
125
|
+
| `code_language` | str | `''` | Default language for code blocks |
|
|
126
|
+
| `heading_style` | str | `'underlined'` | Header style (`'underlined'`, `'atx'`, `'atx_closed'`) |
|
|
127
|
+
| `escape_asterisks` | bool | `True` | Escape * characters |
|
|
128
|
+
| `escape_underscores` | bool | `True` | Escape _ characters |
|
|
129
|
+
| `wrap` | bool | `False` | Enable text wrapping |
|
|
130
|
+
| `wrap_width` | int | `80` | Text wrap width |
|
|
131
|
+
|
|
132
|
+
For a complete list of options, see the [Configuration](#configuration) section below.
|
|
133
|
+
|
|
134
|
+
## CLI Usage
|
|
135
|
+
|
|
136
|
+
Convert HTML files directly from the command line:
|
|
137
|
+
|
|
138
|
+
```shell
|
|
139
|
+
# Convert a file
|
|
140
|
+
html_to_markdown input.html > output.md
|
|
141
|
+
|
|
142
|
+
# Process stdin
|
|
143
|
+
cat input.html | html_to_markdown > output.md
|
|
144
|
+
|
|
145
|
+
# Use custom options
|
|
146
|
+
html_to_markdown --heading-style atx --wrap --wrap-width 100 input.html > output.md
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
View all available options:
|
|
150
|
+
|
|
151
|
+
```shell
|
|
152
|
+
html_to_markdown --help
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Migration from Markdownify
|
|
156
|
+
|
|
157
|
+
For existing projects using Markdownify, a compatibility layer is provided:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
# Old code
|
|
161
|
+
from markdownify import markdownify as md
|
|
162
|
+
|
|
163
|
+
# New code - works the same way
|
|
164
|
+
from html_to_markdown import markdownify as md
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The `markdownify` function is an alias for `convert_to_markdown` and provides identical functionality.
|
|
168
|
+
|
|
169
|
+
## Configuration
|
|
170
|
+
|
|
171
|
+
Full list of configuration options:
|
|
172
|
+
|
|
173
|
+
- `autolinks`: Convert valid URLs to Markdown links automatically
|
|
174
|
+
- `bullets`: Characters to use for bullet points in lists
|
|
175
|
+
- `code_language`: Default language for fenced code blocks
|
|
176
|
+
- `code_language_callback`: Function to determine code block language
|
|
177
|
+
- `convert`: List of HTML tags to convert (None = all supported tags)
|
|
178
|
+
- `default_title`: Use default titles for elements like links
|
|
179
|
+
- `escape_asterisks`: Escape * characters
|
|
180
|
+
- `escape_misc`: Escape miscellaneous Markdown characters
|
|
181
|
+
- `escape_underscores`: Escape _ characters
|
|
182
|
+
- `heading_style`: Header style (underlined/atx/atx_closed)
|
|
183
|
+
- `keep_inline_images_in`: Tags where inline images should be kept
|
|
184
|
+
- `newline_style`: Style for handling newlines (spaces/backslash)
|
|
185
|
+
- `strip`: Tags to remove from output
|
|
186
|
+
- `strong_em_symbol`: Symbol for strong/emphasized text (\* or \_)
|
|
187
|
+
- `sub_symbol`: Symbol for subscript text
|
|
188
|
+
- `sup_symbol`: Symbol for superscript text
|
|
189
|
+
- `wrap`: Enable text wrapping
|
|
190
|
+
- `wrap_width`: Width for text wrapping
|
|
191
|
+
- `convert_as_inline`: Treat content as inline elements
|
|
192
|
+
|
|
193
|
+
## Contribution
|
|
194
|
+
|
|
195
|
+
This library is open to contribution. Feel free to open issues or submit PRs. Its better to discuss issues before
|
|
196
|
+
submitting PRs to avoid disappointment.
|
|
197
|
+
|
|
198
|
+
### Local Development
|
|
199
|
+
|
|
200
|
+
1. Clone the repo
|
|
201
|
+
|
|
202
|
+
1. Install the system dependencies
|
|
203
|
+
|
|
204
|
+
1. Install the full dependencies with `uv sync`
|
|
205
|
+
|
|
206
|
+
1. Install the pre-commit hooks with:
|
|
207
|
+
|
|
208
|
+
```shell
|
|
209
|
+
pre-commit install && pre-commit install --hook-type commit-msg
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
1. Make your changes and submit a PR
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
This library uses the MIT license.
|
|
217
|
+
|
|
218
|
+
## Acknowledgments
|
|
219
|
+
|
|
220
|
+
Special thanks to the original [markdownify](https://pypi.org/project/markdownify/) project creators and contributors.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
html_to_markdown/__init__.py,sha256=95S7_7mR_g88uTnFI0FaRNykrtAaSKb6sJbwSea2zjk,145
|
|
2
|
+
html_to_markdown/__main__.py,sha256=u5xevySlT5eIGyLUaethdDQIKJygaKnc3F2sHWoz75g,264
|
|
3
|
+
html_to_markdown/cli.py,sha256=HVnzmcyrYwah_yWhZ87mZcG0VgnKYp6y89fJh2R-Rlw,4532
|
|
4
|
+
html_to_markdown/constants.py,sha256=Usk67k18tuRovJpKDsiEXdgH20KgqI9KOnK4Fbx-M5c,547
|
|
5
|
+
html_to_markdown/converters.py,sha256=W6Dq2PAwVe5nxE3LSaeO8_hm0eWzSBlRLxf0ryasL6Q,11844
|
|
6
|
+
html_to_markdown/processing.py,sha256=nh_Or-4faI_qh6gF8-xY2qNiqX4eH-jCnBnFpHJbc2M,8632
|
|
7
|
+
html_to_markdown/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
html_to_markdown/utils.py,sha256=HJUDej5HSpXRtYv-OkCyD0hwnPnVfQCwY6rBRlIOt9s,1989
|
|
9
|
+
html_to_markdown-1.2.1.dist-info/METADATA,sha256=-raxzt9vDtzHOOsR0nkbQN-r80V5gRFfeHjDOLWrDwk,6902
|
|
10
|
+
html_to_markdown-1.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
+
html_to_markdown-1.2.1.dist-info/licenses/LICENSE,sha256=3J_HR5BWvUM1mlIrlkF32-uC1FM64gy8JfG17LBuheQ,1122
|
|
12
|
+
html_to_markdown-1.2.1.dist-info/RECORD,,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright 2012-2018 Matthew Tretter
|
|
4
|
-
Copyright 2024 Na'aman Hirschfeld
|
|
4
|
+
Copyright 2024-2025 Na'aman Hirschfeld
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
html_to_markdown/legacy.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING, Literal
|
|
4
|
-
|
|
5
|
-
from html_to_markdown.constants import ASTERISK, SPACES, UNDERLINED
|
|
6
|
-
from html_to_markdown.converters import create_converters_map
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from collections.abc import Callable, Iterable
|
|
10
|
-
|
|
11
|
-
from bs4 import Tag
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _create_legacy_class(
|
|
15
|
-
autolinks: bool,
|
|
16
|
-
bullets: str,
|
|
17
|
-
code_language: str,
|
|
18
|
-
code_language_callback: Callable[[Tag], str] | None,
|
|
19
|
-
default_title: bool,
|
|
20
|
-
heading_style: Literal["atx", "atx_closed", "underlined"],
|
|
21
|
-
keep_inline_images_in: Iterable[str] | None,
|
|
22
|
-
newline_style: str,
|
|
23
|
-
strong_em_symbol: str,
|
|
24
|
-
sub_symbol: str,
|
|
25
|
-
sup_symbol: str,
|
|
26
|
-
wrap: bool,
|
|
27
|
-
wrap_width: int,
|
|
28
|
-
) -> type:
|
|
29
|
-
"""Create a legacy class for Markdownify.
|
|
30
|
-
|
|
31
|
-
Deprecated: Use the new hooks api instead.
|
|
32
|
-
|
|
33
|
-
Args:
|
|
34
|
-
autolinks: Whether to convert URLs into links.
|
|
35
|
-
bullets: The bullet characters to use for unordered lists.
|
|
36
|
-
code_language: The default code language to use.
|
|
37
|
-
code_language_callback: A callback to get the code language.
|
|
38
|
-
default_title: Whether to use the URL as the title for links.
|
|
39
|
-
heading_style: The style of headings.
|
|
40
|
-
keep_inline_images_in: The tags to keep inline images in.
|
|
41
|
-
newline_style: The style of newlines.
|
|
42
|
-
strong_em_symbol: The symbol to use for strong and emphasis text.
|
|
43
|
-
sub_symbol: The symbol to use for subscript text.
|
|
44
|
-
sup_symbol: The symbol to use for superscript text.
|
|
45
|
-
wrap: Whether to wrap text.
|
|
46
|
-
wrap_width: The width to wrap text at.
|
|
47
|
-
|
|
48
|
-
Returns:
|
|
49
|
-
A class that can be used to convert HTML to Markdown.
|
|
50
|
-
"""
|
|
51
|
-
return type(
|
|
52
|
-
"Markdownify",
|
|
53
|
-
(),
|
|
54
|
-
{
|
|
55
|
-
k.removeprefix("_"): v
|
|
56
|
-
for k, v in create_converters_map(
|
|
57
|
-
autolinks=autolinks,
|
|
58
|
-
bullets=bullets,
|
|
59
|
-
code_language=code_language,
|
|
60
|
-
code_language_callback=code_language_callback,
|
|
61
|
-
default_title=default_title,
|
|
62
|
-
heading_style=heading_style,
|
|
63
|
-
keep_inline_images_in=keep_inline_images_in,
|
|
64
|
-
newline_style=newline_style,
|
|
65
|
-
strong_em_symbol=strong_em_symbol,
|
|
66
|
-
sub_symbol=sub_symbol,
|
|
67
|
-
sup_symbol=sup_symbol,
|
|
68
|
-
wrap=wrap,
|
|
69
|
-
wrap_width=wrap_width,
|
|
70
|
-
).items()
|
|
71
|
-
},
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Markdownify = _create_legacy_class(
|
|
76
|
-
autolinks=True,
|
|
77
|
-
bullets="*+-",
|
|
78
|
-
code_language="",
|
|
79
|
-
code_language_callback=None,
|
|
80
|
-
default_title=False,
|
|
81
|
-
heading_style=UNDERLINED,
|
|
82
|
-
keep_inline_images_in=None,
|
|
83
|
-
newline_style=SPACES,
|
|
84
|
-
strong_em_symbol=ASTERISK,
|
|
85
|
-
sub_symbol="",
|
|
86
|
-
sup_symbol="",
|
|
87
|
-
wrap=False,
|
|
88
|
-
wrap_width=80,
|
|
89
|
-
)
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: html-to-markdown
|
|
3
|
-
Version: 1.2.0
|
|
4
|
-
Summary: Convert HTML to markdown
|
|
5
|
-
Author-email: Na'aman Hirschfeld <nhirschfeld@gmail.com>
|
|
6
|
-
License: MIT
|
|
7
|
-
License-File: LICENSE
|
|
8
|
-
Keywords: converter,html,markdown,text-extraction,text-processing
|
|
9
|
-
Classifier: Intended Audience :: Developers
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Operating System :: OS Independent
|
|
12
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
-
Classifier: Topic :: Text Processing
|
|
19
|
-
Classifier: Topic :: Text Processing :: Markup
|
|
20
|
-
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
21
|
-
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
22
|
-
Classifier: Topic :: Utilities
|
|
23
|
-
Classifier: Typing :: Typed
|
|
24
|
-
Requires-Python: >=3.9
|
|
25
|
-
Requires-Dist: beautifulsoup4>=4.12.3
|
|
26
|
-
Description-Content-Type: text/markdown
|
|
27
|
-
|
|
28
|
-
# html_to_markdown
|
|
29
|
-
|
|
30
|
-
This library is a refactored and modernized fork of [markdownify](https://pypi.org/project/markdownify/), supporting
|
|
31
|
-
Python 3.9 and above.
|
|
32
|
-
|
|
33
|
-
### Differences with the Markdownify
|
|
34
|
-
|
|
35
|
-
- The refactored codebase uses a strict functional approach - no classes are involved.
|
|
36
|
-
- There is full typing with strict MyPy strict adherence and a py.typed file included.
|
|
37
|
-
- The `convert_to_markdown` function allows passing a pre-configured instance of `BeautifulSoup` instead of html.
|
|
38
|
-
- This library releases follows standard semver. Its version v1.0.0 was branched from markdownify's v0.13.1, at which
|
|
39
|
-
point versioning is no longer aligned.
|
|
40
|
-
|
|
41
|
-
## Installation
|
|
42
|
-
|
|
43
|
-
```shell
|
|
44
|
-
pip install html_to_markdown
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Usage
|
|
48
|
-
|
|
49
|
-
Convert an string HTML to Markdown:
|
|
50
|
-
|
|
51
|
-
```python
|
|
52
|
-
from html_to_markdown import convert_to_markdown
|
|
53
|
-
|
|
54
|
-
convert_to_markdown('<b>Yay</b> <a href="http://github.com">GitHub</a>') # > '**Yay** [GitHub](http://github.com)'
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Or pass a pre-configured instance of `BeautifulSoup`:
|
|
58
|
-
|
|
59
|
-
```python
|
|
60
|
-
from bs4 import BeautifulSoup
|
|
61
|
-
from html_to_markdown import convert_to_markdown
|
|
62
|
-
|
|
63
|
-
soup = BeautifulSoup('<b>Yay</b> <a href="http://github.com">GitHub</a>', 'lxml') # lxml requires an extra dependency.
|
|
64
|
-
|
|
65
|
-
convert_to_markdown(soup) # > '**Yay** [GitHub](http://github.com)'
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Options
|
|
69
|
-
|
|
70
|
-
The `convert_to_markdown` function accepts the following kwargs:
|
|
71
|
-
|
|
72
|
-
- autolinks (bool): Automatically convert valid URLs into Markdown links. Defaults to True.
|
|
73
|
-
- bullets (str): A string of characters to use for bullet points in lists. Defaults to '\*+-'.
|
|
74
|
-
- code_language (str): Default language identifier for fenced code blocks. Defaults to an empty string.
|
|
75
|
-
- code_language_callback (Callable[[Any], str] | None): Function to dynamically determine the language for code blocks.
|
|
76
|
-
- convert (Iterable[str] | None): A list of tag names to convert to Markdown. If None, all supported tags are converted.
|
|
77
|
-
- default_title (bool): Use the default title when converting certain elements (e.g., links). Defaults to False.
|
|
78
|
-
- escape_asterisks (bool): Escape asterisks (\*) to prevent unintended Markdown formatting. Defaults to True.
|
|
79
|
-
- escape_misc (bool): Escape miscellaneous characters to prevent conflicts in Markdown. Defaults to True.
|
|
80
|
-
- escape*underscores (bool): Escape underscores (*) to prevent unintended italic formatting. Defaults to True.
|
|
81
|
-
- heading_style (Literal["underlined", "atx", "atx_closed"]): The style to use for Markdown headings. Defaults to "
|
|
82
|
-
underlined".
|
|
83
|
-
- keep_inline_images_in (Iterable[str] | None): Tags in which inline images should be preserved. Defaults to None.
|
|
84
|
-
- newline_style (Literal["spaces", "backslash"]): Style for handling newlines in text content. Defaults to "spaces".
|
|
85
|
-
- strip (Iterable[str] | None): Tags to strip from the output. Defaults to None.
|
|
86
|
-
- strong*em_symbol (Literal["\*", "*"]): Symbol to use for strong/emphasized text. Defaults to "\*".
|
|
87
|
-
- sub_symbol (str): Custom symbol for subscript text. Defaults to an empty string.
|
|
88
|
-
- sup_symbol (str): Custom symbol for superscript text. Defaults to an empty string.
|
|
89
|
-
- wrap (bool): Wrap text to the specified width. Defaults to False.
|
|
90
|
-
- wrap_width (int): The number of characters at which to wrap text. Defaults to 80.
|
|
91
|
-
- convert_as_inline (bool): Treat the content as inline elements (no block elements like paragraphs). Defaults to False.
|
|
92
|
-
|
|
93
|
-
## CLI
|
|
94
|
-
|
|
95
|
-
For compatibility with the original markdownify, a CLI is provided. Use `html_to_markdown example.html > example.md` or
|
|
96
|
-
pipe input from stdin:
|
|
97
|
-
|
|
98
|
-
```shell
|
|
99
|
-
cat example.html | html_to_markdown > example.md
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
Use `html_to_markdown -h` to see all available options. They are the same as listed above and take the same arguments.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
html_to_markdown/__init__.py,sha256=cXm4YOyrAp2HKHMDfnVA5e75zg6wdqpyXugjBYvBMFc,143
|
|
2
|
-
html_to_markdown/__main__.py,sha256=u5xevySlT5eIGyLUaethdDQIKJygaKnc3F2sHWoz75g,264
|
|
3
|
-
html_to_markdown/cli.py,sha256=HVnzmcyrYwah_yWhZ87mZcG0VgnKYp6y89fJh2R-Rlw,4532
|
|
4
|
-
html_to_markdown/constants.py,sha256=Usk67k18tuRovJpKDsiEXdgH20KgqI9KOnK4Fbx-M5c,547
|
|
5
|
-
html_to_markdown/converters.py,sha256=hW4RqAbgx0tdTzfUSvAGQg1OgQUmHL1cekZtJLFq_Ns,12080
|
|
6
|
-
html_to_markdown/legacy.py,sha256=vL-MVKPXOue-JJafXFtmGcVIPylwmPOly0CELTSzWRQ,2773
|
|
7
|
-
html_to_markdown/processing.py,sha256=L1wZwUm7WA8wN4GA5zjCStwACb-8S2scQZPbzeHgdY8,8951
|
|
8
|
-
html_to_markdown/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
html_to_markdown/utils.py,sha256=HJUDej5HSpXRtYv-OkCyD0hwnPnVfQCwY6rBRlIOt9s,1989
|
|
10
|
-
html_to_markdown-1.2.0.dist-info/METADATA,sha256=Dg2ZibNWNW_GyszXG2bxT-oOtOJc8iryVxlLn38eMww,4709
|
|
11
|
-
html_to_markdown-1.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
-
html_to_markdown-1.2.0.dist-info/licenses/LICENSE,sha256=06BS7zd6oPCrbzAqrThGFboRlbssgBsqDJGqKyZW2Og,1117
|
|
13
|
-
html_to_markdown-1.2.0.dist-info/RECORD,,
|
|
File without changes
|