Convert HTML to clean Markdown.
npm install html-to-markdownimport { htmlToMarkdown } from 'html-to-markdown';
const html = `
<h1>Title</h1>
<p>Some <strong>bold</strong> and <em>italic</em> text.</p>
<pre><code class="language-js">console.log('Hello');</code></pre>
`;
const markdown = htmlToMarkdown(html);
// # Title
//
// Some **bold** and *italic* text.
//
// ```js
// console.log('Hello');
// ```htmlToMarkdown(html, {
// Keep certain HTML tags
keepTags: ['iframe', 'video'],
// Remove certain elements
removeTags: ['script', 'style', 'nav'],
// Code block style
codeBlockStyle: 'fenced', // or 'indented'
// Heading style
headingStyle: 'atx', // or 'setext'
// Link style
linkStyle: 'inlined', // or 'referenced'
// Image handling
downloadImages: true,
imageDir: './images',
});- Web scraping to Markdown
- Convert blog posts for static sites
- Documentation migration
- Content extraction
MIT