Extracts HTML tables and converts them to Markdown, preserving structure via row/colspan handling.
Project description
html-table2md
A robust Python tool to extract complex HTML tables and convert them into clean Markdown, JSON, or CSV formats.
Unlike simple formatters, this library features a Grid Logic Solver that correctly interprets rowspan and colspan attributes, normalizing complex HTML grids into perfectly aligned data structures.
How is this different from other table2md packages?
There is an existing package called table2md on PyPI.
-
The existing package is a formatter. You feed it Python lists/dicts, and it draws a Markdown table.
-
This package is an extractor and parser. It takes raw HTML source code, uses
BeautifulSoupto parse the tags, mathematically resolves complex cell spans (rowspans/colspans), and builds an internal representation before exporting to Markdown.
Architecture
Our pipeline ensures that complex HTML structures are safely converted without data loss or misalignment:
graph TD
n1["HTML Input"] --> n2["BeautifulSoup Parser"]
n2 --> n3["Grid Logic<br>(Rowspan/Colspan Solver)"]
n3 --> n4["ParsedTable Data Object"]
n4 --> n5["Markdown Export"]
n4 --> n6["JSON/CSV Export"]
n4 --> n7["LangChain/LlamaIndex Wrappers"]
Installation
pip install html-table2md
Quick Start
from table2md.core import TableParser
html_content = """
<table border="1">
<tr>
<th colspan="2">Header</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
"""
# Initialize parser with your HTML
parser = TableParser(html_content)
# Parse all tables in the HTML
tables = parser.parse()
if tables:
table = tables[0]
# Export to Markdown (perfect for LLM context windows)
print(table.to_markdown())
# Export to JSON
# print(table.to_json())
# Export to CSV
# print(table.to_csv())
Features
- HTML parsing via
BeautifulSoup - Recursive inline-tag formatting (keeps links, bold, and italic tags alive even if nested in divs)
- Complex
rowspanandcolspangrid resolution (using flexible strategies like filling cells with "dito" to preserve context for LLMs) - Clean Markdown export
- Data Exports: JSON and CSV serialization from the
ParsedTableobject - AI Integrations: Includes a ready-to-use
LangChainDocument Loader
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file html_table_rescuer-0.1.0.tar.gz.
File metadata
- Download URL: html_table_rescuer-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1039e288d2b06308d79d5075fe73312067cbffe7e706096878fde6519f376ce
|
|
| MD5 |
134e38dc66ea14f4084123991705df99
|
|
| BLAKE2b-256 |
b4b6ebd781bbb3695ba1f5c963a93c987af6ed50dd05d0a37f9aac830d7a7f9a
|
Provenance
The following attestation bundles were made for html_table_rescuer-0.1.0.tar.gz:
Publisher:
publish.yml on Encephos/table2md
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
html_table_rescuer-0.1.0.tar.gz -
Subject digest:
d1039e288d2b06308d79d5075fe73312067cbffe7e706096878fde6519f376ce - Sigstore transparency entry: 2280177855
- Sigstore integration time:
-
Permalink:
Encephos/table2md@31fcf9885de82d8de3c40b36bebef5481374775c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Encephos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@31fcf9885de82d8de3c40b36bebef5481374775c -
Trigger Event:
release
-
Statement type:
File details
Details for the file html_table_rescuer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: html_table_rescuer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebc4ce6c821b970fcca030fb8d67514c79b2ff18fb8d62c8e5a41948f5b4734d
|
|
| MD5 |
942914a5262d39cdb9640ed8631ca492
|
|
| BLAKE2b-256 |
012218f15a584a185581a2d8b5a2d34d2746d11690d9088c65b41267775b23a3
|
Provenance
The following attestation bundles were made for html_table_rescuer-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Encephos/table2md
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
html_table_rescuer-0.1.0-py3-none-any.whl -
Subject digest:
ebc4ce6c821b970fcca030fb8d67514c79b2ff18fb8d62c8e5a41948f5b4734d - Sigstore transparency entry: 2280177900
- Sigstore integration time:
-
Permalink:
Encephos/table2md@31fcf9885de82d8de3c40b36bebef5481374775c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Encephos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@31fcf9885de82d8de3c40b36bebef5481374775c -
Trigger Event:
release
-
Statement type: