소개
HTML을 Markdown으로 변환합니다.
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originaltomd
Convert real-world HTML to clean Markdown.
tomd is a small, fast Python library that turns an HTML string into
Markdown — handy for archiving articles, normalising scraped content,
piping rendered pages into LLM context, or anywhere you'd rather work
with plain text than a DOM.
It walks the parsed tree with lxml, so it handles nested lists,
formatted table cells, fenced code blocks with language hints, HTML
entities, hard line breaks, and the messy markup you actually find in
the wild.
Install
pip install tomd
# or
uv add tomd
Requires Python 3.10+.
Quickstart
import tomd
tomd.convert("<h1>Hello, world!</h1>")
# => '# Hello, world!\n'
Or via the class:
from tomd import Tomd
Tomd("<p><b>bold</b> and <i>italic</i></p>").markdown
# => '**bold** and *italic*\n'
What it converts
| Markdown | HTML |
|---|---|
| Headings | <h1>–<h6> |
| Bold / italic | <b>, <strong>, <i>, <em> |
| Strikethrough | <del>, <s>, <strike> |
| Inline code | <code>, <kbd>, <samp> |
| Links | <a href="..."> incl. relative, mailto:, title |
| Images | <img src="..." alt="..." title="..."/> |
| Lists (nested, mixed) | <ul>, <ol start="N">, <li> |
| Blockquotes | <blockquote> (incl. nested, multi-paragraph) |
| Horizontal rule | <hr/> |
| Fenced code blocks | <pre><code class="language-X"> |
| Tables | <table> with or without <thead>/<tbody> |
| Hard line breaks | <br/> → \n |
| Definition lists | <dl> / <dt> / <dd> |
<script>, <style>, <iframe>, <head>, and friends are stripped.
HTML entities (&, —, <) are decoded. Unknown tags
fall through to their text content.
Example
from tomd import Tomd
html = """
<article>
<h1>Heading</h1>
<p><b>bold</b>, <i>italic</i>, and a <a href="https://example.com">link</a>.</p>
<ul>
<li>one</li>
<li>two
<ul><li>nested</li></ul>
</li>
</ul>
<pre><code class="language-python">print("hi")</code></pre>
</article>
"""
print(Tomd(html).markdown)
# Heading
**bold**, *italic*, and a [link](https://example.com).
- one
- two
- nested
```python
print("hi")
```
Development
git clone https://github.com/elliotgao2/tomd.git
cd tomd
uv sync # install deps into .venv
uv run pytest # run tests
uv run ruff check . # lint
uv run ruff format --check . # format check
Install the pre-commit hooks:
uv run pre-commit install
Contributing
Pull requests are welcome. For non-trivial changes, please open an issue
first. Make sure uv run pytest, uv run ruff check ., and
uv run ruff format --check . all pass before submitting.
License
MIT © Elliot Gao
관련 프로젝트 살펴보기
불러오는 중…