Gathering detailed insights and metrics for @bmewburn/turndown
Gathering detailed insights and metrics for @bmewburn/turndown
Gathering detailed insights and metrics for @bmewburn/turndown
Gathering detailed insights and metrics for @bmewburn/turndown
🛏 An HTML to Markdown converter written in JavaScript
npm install @bmewburn/turndown
Typescript
Module System
Node Version
NPM Version
76.3
Supply Chain
98.6
Quality
74.7
Maintenance
100
Vulnerability
100
License
HTML (53.92%)
JavaScript (46.08%)
Total Downloads
107,782
Last Day
1
Last Week
4
Last Month
19
Last Year
382
MIT License
9,761 Stars
448 Commits
917 Forks
123 Watchers
15 Branches
27 Contributors
Updated on May 29, 2025
Minified
Minified + Gzipped
Latest Version
5.0.3
Package Id
@bmewburn/turndown@5.0.3
Unpacked Size
169.84 kB
Size
12.18 kB
File Count
10
NPM Version
6.9.0
Node Version
10.15.3
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-20%
4
Compared to previous week
Last Month
-5%
19
Compared to previous month
Last Year
-64.7%
382
Compared to previous year
Convert HTML into Markdown with JavaScript.
npm:
npm install turndown
Browser:
1<script src="https://unpkg.com/turndown/dist/turndown.js"></script>
For usage with RequireJS, UMD versions are located in lib/turndown.umd.js
(for Node.js) and lib/turndown.browser.umd.js
for browser usage. These files are generated when the npm package is published. To generate them manually, clone this repo and run npm run build
.
1// For Node.js 2var TurndownService = require('turndown') 3 4var turndownService = new TurndownService() 5var markdown = turndownService.turndown('<h1>Hello world!</h1>')
Turndown also accepts DOM nodes as input (either element nodes, document nodes, or document fragment nodes):
1var markdown = turndownService.turndown(document.getElementById('content'))
Options can be passed in to the constructor on instantiation. For example:
1var turndownService = new TurndownService({ option: 'value' })
Option | Valid values | Default |
---|---|---|
headingStyle | setext or atx | setext |
hr | Any Thematic break | * * * |
bulletListMarker | - , + , or * | * |
codeBlockStyle | indented or fenced | indented |
fence | ``` or ~~~ | ``` |
emDelimiter | _ or * | _ |
strongDelimiter | ** or __ | ** |
linkStyle | inlined or referenced | inlined |
linkReferenceStyle | full , collapsed , or shortcut | full |
Option | Valid values | Default |
---|---|---|
blankReplacement | rule replacement function | See Special Rules below |
keepReplacement | rule replacement function | See Special Rules below |
defaultReplacement | rule replacement function | See Special Rules below |
addRule(key, rule)
The key
parameter is a unique name for the rule for easy reference. Example:
1turndownService.addRule('strikethrough', { 2 filter: ['del', 's', 'strike'], 3 replacement: function (content) { 4 return '~' + content + '~' 5 } 6})
addRule
returns the TurndownService
instance for chaining.
See Extending with Rules below.
keep(filter)
Determines which elements are to be kept and rendered as HTML. By default, Turndown does not keep any elements. The filter parameter works like a rule filter (see section on filters belows). Example:
1turndownService.keep(['del', 'ins']) 2turndownService.turndown('<p>Hello <del>world</del><ins>World</ins></p>') // 'Hello <del>world</del><ins>World</ins>'
This will render <del>
and <ins>
elements as HTML when converted.
keep
can be called multiple times, with the newly added keep filters taking precedence over older ones. Keep filters will be overridden by the standard CommonMark rules and any added rules. To keep elements that are normally handled by those rules, add a rule with the desired behaviour.
keep
returns the TurndownService
instance for chaining.
remove(filter)
Determines which elements are to be removed altogether i.e. converted to an empty string. By default, Turndown does not remove any elements. The filter parameter works like a rule filter (see section on filters belows). Example:
1turndownService.remove('del') 2turndownService.turndown('<p>Hello <del>world</del><ins>World</ins></p>') // 'Hello World'
This will remove <del>
elements (and contents).
remove
can be called multiple times, with the newly added remove filters taking precedence over older ones. Remove filters will be overridden by the keep filters, standard CommonMark rules, and any added rules. To remove elements that are normally handled by those rules, add a rule with the desired behaviour.
remove
returns the TurndownService
instance for chaining.
use(plugin|array)
Use a plugin, or an array of plugins. Example:
1// Import plugins from turndown-plugin-gfm 2var turndownPluginGfm = require('turndown-plugin-gfm') 3var gfm = turndownPluginGfm.gfm 4var tables = turndownPluginGfm.tables 5var strikethrough = turndownPluginGfm.strikethrough 6 7// Use the gfm plugin 8turndownService.use(gfm) 9 10// Use the table and strikethrough plugins only 11turndownService.use([tables, strikethrough])
use
returns the TurndownService
instance for chaining.
See Plugins below.
Turndown can be extended by adding rules. A rule is a plain JavaScript object with filter
and replacement
properties. For example, the rule for converting <p>
elements is as follows:
1{ 2 filter: 'p', 3 replacement: function (content) { 4 return '\n\n' + content + '\n\n' 5 } 6}
The filter selects <p>
elements, and the replacement function returns the <p>
contents separated by two new lines.
filter
String|Array|FunctionThe filter property determines whether or not an element should be replaced with the rule's replacement
. DOM nodes can be selected simply using a tag name or an array of tag names:
filter: 'p'
will select <p>
elementsfilter: ['em', 'i']
will select <em>
or <i>
elementsAlternatively, the filter can be a function that returns a boolean depending on whether a given node should be replaced. The function is passed a DOM node as well as the TurndownService
options. For example, the following rule selects <a>
elements (with an href
) when the linkStyle
option is inlined
:
1filter: function (node, options) { 2 return ( 3 options.linkStyle === 'inlined' && 4 node.nodeName === 'A' && 5 node.getAttribute('href') 6 ) 7}
replacement
FunctionThe replacement function determines how an element should be converted. It should return the Markdown string for a given node. The function is passed the node's content, the node itself, and the TurndownService
options.
The following rule shows how <em>
elements are converted:
1rules.emphasis = { 2 filter: ['em', 'i'], 3 4 replacement: function (content, node, options) { 5 return options.emDelimiter + content + options.emDelimiter 6 } 7}
Blank rule determines how to handle blank elements. It overrides every rule (even those added via addRule
). A node is blank if it only contains whitespace, and it's not an <a>
, <td>
,<th>
or a void element. Its behaviour can be customised using the blankReplacement
option.
Keep rules determine how to handle the elements that should not be converted, i.e. rendered as HTML in the Markdown output. By default, no elements are kept. Block-level elements will be separated from surrounding content by blank lines. Its behaviour can be customised using the keepReplacement
option.
Remove rules determine which elements to remove altogether. By default, no elements are removed.
Default rule handles nodes which are not recognised by any other rule. By default, it outputs the node's text content (separated by blank lines if it is a block-level element). Its behaviour can be customised with the defaultReplacement
option.
Turndown iterates over the set of rules, and picks the first one that matches the filter
. The following list describes the order of precedence:
The plugin API provides a convenient way for developers to apply multiple extensions. A plugin is just a function that is called with the TurndownService
instance.
Turndown uses backslashes (\
) to escape Markdown characters in the HTML input. This ensures that these characters are not interpreted as Markdown when the output is compiled back to HTML. For example, the contents of <h1>1. Hello world</h1>
needs to be escaped to 1\. Hello world
, otherwise it will be interpreted as a list item rather than a heading.
To avoid the complexity and the performance implications of parsing the content of every HTML element as Markdown, Turndown uses a group of regular expressions to escape potential Markdown syntax. As a result, the escaping rules can be quite aggressive.
TurndownService.prototype.escape
If you are confident in doing so, you may want to customise the escaping behaviour to suit your needs. This can be done by overriding TurndownService.prototype.escape
. escape
takes the text of each HTML element and should return a version with the Markdown characters escaped.
Note: text in code elements is never passed toescape
.
turndown is copyright © 2017+ Dom Christie and released under the MIT license.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
Found 7/23 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-26
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More