Socket
Socket
Sign inDemoInstall

turndown

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turndown

A library that converts HTML to Markdown


Version published
Weekly downloads
880K
increased by1.48%
Maintainers
2
Weekly downloads
 
Created

What is turndown?

Turndown is a library that converts HTML into Markdown. It provides a simple API to transform HTML strings into Markdown format, making it useful for applications that need to convert rich text content into a more readable and lightweight format.

What are turndown's main functionalities?

Basic HTML to Markdown Conversion

This feature allows you to convert basic HTML elements into their Markdown equivalents. In this example, an HTML heading is converted into a Markdown heading.

const TurndownService = require('turndown');
const turndownService = new TurndownService();
const markdown = turndownService.turndown('<h1>Hello World</h1>');
console.log(markdown); // # Hello World

Custom Rules

Turndown allows you to add custom rules for converting specific HTML elements. In this example, a custom rule is added to convert <del>, <s>, and <strike> tags into Markdown strikethrough syntax.

const TurndownService = require('turndown');
const turndownService = new TurndownService();
turndownService.addRule('strikethrough', {
  filter: ['del', 's', 'strike'],
  replacement: function (content) {
    return '~~' + content + '~~';
  }
});
const markdown = turndownService.turndown('<del>Deleted text</del>');
console.log(markdown); // ~~Deleted text~~

Handling Complex HTML Structures

Turndown can handle complex HTML structures and convert them into Markdown. This example demonstrates converting a nested HTML structure with headings, paragraphs, and inline formatting.

const TurndownService = require('turndown');
const turndownService = new TurndownService();
const html = '<div><h1>Title</h1><p>This is a <strong>paragraph</strong> with <em>emphasis</em>.</p></div>';
const markdown = turndownService.turndown(html);
console.log(markdown); // # Title\n\nThis is a **paragraph** with *emphasis*.

Other packages similar to turndown

Keywords

FAQs

Package last updated on 28 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc