site2md
v1.1.0
Published
HTML to Markdown converter - works in browser and Node.js
Maintainers
Readme
site2md
HTML to Markdown converter. Works in browser and Node.js.
Install
npm install site2mdUsage
Browser / React / Node.js (as library)
import { htmlToMarkdown, markdownToHTML } from 'site2md'
// HTML → Markdown
const md = htmlToMarkdown('<h1>Hello</h1><p>World</p>')
// Output: # Hello\n\nWorld
// Markdown → HTML
const html = markdownToHTML('# Hello\n\nWorld')
// Output: <h1>Hello</h1><p>World</p>React example
import { htmlToMarkdown } from 'site2md'
function MarkdownPreview({ html }) {
const markdown = htmlToMarkdown(html)
return <pre>{markdown}</pre>
}Options
htmlToMarkdown(html, {
source: 'auto' // 'auto' | 'medium' | 'devto' | 'notion' | 'generic'
})CLI
The command is md:
# From URL
md --url "https://some-blog.com/post"
# From file
md article.html
# Pipe
curl -s "https://site.com" | md
# Save to file
md --url "https://site.com" -o output.md
# Reverse (markdown to HTML)
md --html README.md
# Render JS first (for SPAs like React/Next.js)
md --url "https://spa-site.com" --renderCLI Options
--url <url> Fetch URL and convert
--render Use headless browser to render JS first (requires Chrome)
--output, -o Write to file instead of stdout
--source <type> Platform hint: auto, medium, devto, notion, generic
--html Reverse mode: markdown to HTML
--help Show helpWhat it handles
- Code blocks with language detection
- Nested lists
- Tables
- Images (including images inside links)
- Blockquotes
- HTML entities
- Platform-specific markup (Medium, dev.to, Notion exports)
Browser vs CLI
| Feature | Browser/React | CLI | |---------|--------------|-----| | htmlToMarkdown() | ✓ | ✓ | | markdownToHTML() | ✓ | ✓ | | Fetch URLs | ✗ | ✓ | | Render JS (--render) | ✗ | ✓ |
The core converter is dependency-free and works everywhere. The CLI adds URL fetching and optional JS rendering via puppeteer.
License
MIT
