A Clojure library for converting HTML (e.g. from websites) into clean Markdown that is both human readable and LLM token-efficient.
(require '[html-to-md.core :as html-to-md])
(html-to-md/convert "<h1>Some heading</h1> <p>Followed by some text</p>")
; "# Some heading\n\nFollowed by some text"
Use it as a cli tool via bbin:
bbin install https://github.com/jacobemcken/html-to-md.git
The use it like:
html-to-md https://www.emcken.dk
Running test suite using vanilla Clojure:
clj -X:test
Running test suite using Babashka:
bb test
Build the artifact:
clj -T:build
Install in local Maven cache:
clj -T:build install
The library converts HTML to Markdown in two steps: HTML to Hiccup (via Hickory) and then Hiccup to Markdown.
See docs/architecture.md for details.
Notice how irrelevant whitespace is trimmed in the following examples.
<span> Some text</span><span>!</span> <span>More</span><span> text</span>.
becomes:
Some text! More text.
<p>Some text!</p><p>More text,
across multiple lines.</p>
becomes:
Some text!
More text,
across multiple lines.
<ul>
<li>Apple</li>
<li>Banana
<ol>
<li>The <code>yellow</code> one.</li>
<li><div><blockquote><p>A <em>sunflower</em> would
<span style="color:purple;">be jealous</span>.
</p><p><strong>Even</strong><br>the sun.</p></blockquote></div></li>
</ol>
</li>
<li>Kiwi</li>
</ul>
becomes:
- Apple
- Banana
1. The `yellow` one.
2. > A _sunflower_ would be jealous.
>
> **Even**
> the sun.
- Kiwi
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |