{"id":11428,"library":"node-html-markdown","title":"HTML to Markdown Converter","description":"node-html-markdown is a high-performance, cross-platform library designed for converting HTML content into Markdown, compatible with both Node.js and browser environments. The current stable version is 2.0.0. The library's primary focus is on speed, with benchmarks indicating significantly faster conversion rates compared to popular alternatives like Turndown. Additionally, it emphasizes generating human-readable Markdown output by producing clean, concise results with consistent spacing, aiming to avoid common formatting issues such as excessive line breaks. While it does not adhere to a rigid release schedule, the project is actively maintained, with regular updates that have historically included features like table support and fixes for browser compatibility, ensuring its reliability for converting large volumes of HTML data.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/crosstype/node-html-markdown","tags":["javascript","html","markdown","converter","md","html5","node-html-parser","fast-html-parser","turndown","typescript"],"install":[{"cmd":"npm install node-html-markdown","lang":"bash","label":"npm"},{"cmd":"yarn add node-html-markdown","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-html-markdown","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily targets ESM. For CJS environments, ensure proper transpilation or use a bundler.","wrong":"const NodeHtmlMarkdown = require('node-html-markdown')","symbol":"NodeHtmlMarkdown","correct":"import { NodeHtmlMarkdown } from 'node-html-markdown'"},{"note":"Use this interface for type-safe configuration of the converter instance.","symbol":"NodeHtmlMarkdownOptions","correct":"import { NodeHtmlMarkdownOptions } from 'node-html-markdown'"},{"note":"For single-use conversions, the static `translate` method is convenient. For multiple conversions, create an instance for performance.","wrong":"const nhm = new NodeHtmlMarkdown(); nhm.translate(htmlString); // if only used once","symbol":"translate (static)","correct":"NodeHtmlMarkdown.translate(htmlString)"}],"quickstart":{"code":"import { NodeHtmlMarkdown } from 'node-html-markdown';\n\n// Initialize with options for a reusable instance\n// Custom options can improve output or handle specific HTML structures.\nconst nhm = new NodeHtmlMarkdown(\n  {\n    codeFence: '```', // Customize code block fence (default: ```)\n    bulletMarker: '-', // Use hyphens for list bullets (default: *)\n    codeBlockStyle: 'fenced', // Prefer fenced code blocks (default: fenced)\n    preferNativeParser: typeof window !== 'undefined' // Use native DOMParser in browsers if available\n  },\n  /* customTranslators (optional) */ undefined,\n  /* customCodeBlockTranslators (optional) */ undefined\n);\n\n// Example HTML input to be converted\nconst htmlContent = `\n  <h1>Welcome to my document</h1>\n  <p>This is a <b>paragraph</b> with <i>some emphasis</i> and a <s>strikethrough</s> word.</p>\n  <ul>\n    <li>First item in a list.</li>\n    <li>Second item.</li>\n  </ul>\n  <pre><code>function greet() {\n  console.log('Hello, world!');\n}\ngreet();</code></pre>\n  <p>Check out our <a href=\"https://example.com/docs\">documentation</a>.</p>\n  <table><thead><tr><th>Header 1</th><th>Header 2</th></tr></thead><tbody><tr><td>Data 1</td><td>Data 2</td></tr></tbody></table>\n`;\n\n// Convert a single HTML string to Markdown\nconst markdownOutput = nhm.translate(htmlContent);\nconsole.log('Converted Markdown Output:\\n');\nconsole.log(markdownOutput);\n\n// The instance can be reused for multiple conversions efficiently\nconst anotherHtml = '<div><p>Another piece of HTML.</p></div>';\nconst anotherMarkdown = nhm.translate(anotherHtml);\nconsole.log('\\nAnother Converted Markdown:\\n');\nconsole.log(anotherMarkdown);","lang":"typescript","description":"Demonstrates initializing a reusable instance of `NodeHtmlMarkdown` with custom options and using it to convert both single and multiple HTML strings to Markdown efficiently."},"warnings":[{"fix":"Review HTML input for elements inside code blocks that might have previously been implicitly handled. Adjust HTML or use custom translators if specific parsing behavior for these elements is desired within code blocks.","message":"Version 2.0.0 introduces a breaking change by explicitly denying special handling for certain elements that should not be present inside code blocks. This can affect how HTML within `<pre><code>` tags is rendered.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always create a single `new NodeHtmlMarkdown()` instance and reuse it for all subsequent `translate()` calls in performance-critical applications or when converting many HTML strings.","message":"The `NodeHtmlMarkdown` instance performs better when reused for multiple conversions. Instantiating a new converter for every conversion carries an overhead that can impact performance, especially with large volumes of data.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"When running in a browser, initialize `NodeHtmlMarkdown` with `{ preferNativeParser: true }` in the options object to utilize the browser's native HTML parsing capabilities.","message":"For browser environments, the `preferNativeParser` option defaults to `false`. Setting it to `true` can leverage the native `DOMParser` for potentially better performance and compatibility.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your Node.js environment is upgraded to version 20.0.0 or newer. Check your `package.json` engines field and update CI/CD configurations accordingly.","message":"Version 2.0.0 explicitly requires Node.js version 20.0.0 or higher. Running on older Node.js versions will result in runtime errors or unexpected behavior.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm"}