Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

turndown

Package Overview
Dependencies
Maintainers
1
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

  • 4.0.0-rc.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
844K
decreased by-4.53%
Maintainers
1
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 10 Nov 2017

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