Skip to content

Convert HTML to clean Markdown. Handles tables, code blocks, images. Perfect for web scraping.

Notifications You must be signed in to change notification settings

jy02140251/html-to-markdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

HTML to Markdown

Convert HTML to clean Markdown.

Installation

npm install html-to-markdown

Quick Start

import { 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');
// ```

Options

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',
});

Use Cases

  • Web scraping to Markdown
  • Convert blog posts for static sites
  • Documentation migration
  • Content extraction

License

MIT

About

Convert HTML to clean Markdown. Handles tables, code blocks, images. Perfect for web scraping.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published