HTML to Markdown Converter With Pure JavaScript – Turndown
1. Install the Turndown with NPM:
# NPM $ npm install turndown --save
2. Import the Turndown into your module.
// ES 6
import TurndownService from 'turndown';
// CommonJS:
const TurndownService = require('turndown'); 3. For browser, include the JavaScript file ‘turndown.js’ on the webpage.
<script src="https://unpkg.com/turndown/dist/turndown.js"></script>
4. Create a new Turndown instance.
const turndownService = new TurndownService()
5. Convert any HTML markup to Markdown.
const markdown = turndownService.turndown('<h1>Hello world!</h1>') 6. Available options to customize the markdown editor.
new TurndownService({
rules: COMMONMARK_RULES,
headingStyle: 'setext',
hr: '* * *',
bulletListMarker: '*',
codeBlockStyle: 'indented',
fence: '```',
emDelimiter: '_',
strongDelimiter: '**',
linkStyle: 'inlined',
linkReferenceStyle: 'full',
br: ' ',
blankReplacement: function (content, node) {
return node.isBlock ? 'nn' : ''
},
keepReplacement: function (content, node) {
return node.isBlock ? 'nn' + node.outerHTML + 'nn' : node.outerHTML
},
defaultReplacement: function (content, node) {
return node.isBlock ? 'nn' + content + 'nn' : content
}
}) 7. Add a custom rule to the converter.
turndownService.addRule('rule-name', {
// your own rule here
}) 8. You’re able to specify the html elements which should be kept while converting.
turndownService.keep(['del', 'ins'])
v7.2.3 (04/03/2026)
v7.2.0 (05/19/2024)
v7.1.3 (03/15/2024)
v7.1.2 (03/22/2023)
v7.1.1 (06/30/2021)
v6.0.0 (03/12/2019)
v5.0.3 (01/31/2019)
v5.0.1 (10/31/2018)
The post HTML to Markdown Converter With Pure JavaScript – Turndown appeared first on CSS Script.
Jack Black has a clear idea who he would like to play in Red Dead…
Proximity Media, the company co-founded by Sinners mastermind Ryan Coogler, is working on an Animorphs…
If you're planning out a PC build and have been hoping to get one of…
Security researchers at watchTowr Labs have disclosed a critical exploit chain targeting the Progress ShareFile…
Microsoft has launched an automated, machine-learning-driven rollout to forcibly upgrade unmanaged Windows 11 Home and…
A former core infrastructure engineer has pleaded guilty to federal hacking and extortion charges after…
This website uses cookies.