document2md.tables¶
Turns the raw HTML tables mineru emits into Markdown tables.
Turn the raw HTML tables mineru emits into Markdown tables.
mineru renders simple tables as Markdown but falls back to raw HTML
(<table>…</table> with rowspan/colspan) for anything complex. This module
rewrites those HTML tables into GitHub Markdown tables so document2md’s output is
Markdown all the way through — no leftover HTML.
Implemented with the standard library’s html.parser only (no BeautifulSoup)
to keep document2md’s dependencies to just requests and mineru.
- html_tables_to_markdown(text: str) str[source]¶
Replace every
<table>…</table>block in text with a GitHub Markdown table, leaving everything else untouched. Blank lines are ensured around each converted table so it renders as a table.
- class _TableParser[source]¶
Collect a single HTML table’s cells as rows of (text, attrs).
- __init__()[source]¶
Initialize and reset this instance.
If convert_charrefs is true (the default), all character references are automatically converted to the corresponding Unicode characters.
If scripting is false (the default), the content of the
noscriptelement is parsed normally; if it’s true, it’s returned as is without being parsed.
- handle_starttag(tag, attrs)[source]¶
Open a new row on <tr>, a new cell (recording its attrs, for rowspan/colspan) on <td>/<th>, and turn <br> inside a cell into a space so wrapped lines don’t run together.
- _parse_rows(fragment: str) list[list[tuple[str, dict]]][source]¶
Parse a single
<table>…</table>fragment into _TableParser’s row structure.
- _span(attrs: dict, name: str) int[source]¶
Read attrs[name] (rowspan/colspan) as a positive int, defaulting to 1 when it is missing or not a valid integer.
- _clean_cell(text: str) str[source]¶
Collapse a cell’s whitespace to single spaces and escape | so it can’t be mistaken for a Markdown table column separator.