npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

markdown-read

v3.8.0

Published

turn url or html file to markdown

Downloads

34

Readme

Markdown Read

npm version GitHub issues GitHub stars npm downloads TypeScript node version code size install size npm bundle size npm bundle size dependencies tree shaking

Convert any URL to Markdown.

Try it online: HTML To Markdown

Tech Stack

  • @mozilla/readability for read meaning html
  • turndown for html to markdown
  • jsdom for parse html

Usage

You will need Node.js installed on your system, then install it globally.

$ npm i -g markdown-read

# Turn current page to markdown
$ markdown https://example.com
## Example Domain

This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.

[More information...](https://www.iana.org/domains/example)

Options

  • --header: Add custom headers to the request. This can be useful for setting user-agent strings or other HTTP headers required by the target website.

Example:

$ markdown https://httpbin.org/get --header 'User-Agent: Markdown Reader'

API Reference

markdown(url: string, options?: MarkdownOptions): Promise<MarkdownContent | null>

Converts a web page to Markdown format.

  • url: The URL of the web page to convert
  • options: Optional settings for document retrieval and Markdown conversion
    • headers: Additional headers to include in the request
    • fetcher: Custom function to fetch the HTML content
    • All options from TurndownOptions are also supported

Returns a Promise that resolves to a MarkdownContent object or null if conversion fails.

MarkdownContent

The MarkdownContent object extends ReadabilityContent and includes:

  • markdown: The converted Markdown content
  • length: The length of the Markdown content
  • url: The original URL of the web page

turndown(html: string, options?: TurndownOptions): string

Converts HTML content to Markdown.

  • html: The HTML string to convert
  • options: Optional settings for Turndown conversion. These options will override the default settings.

Returns the Markdown representation of the input HTML.

Default Options

{
  emDelimiter: '*',
  codeBlockStyle: 'fenced',
  fence: '```',
  headingStyle: 'atx',
  bulletListMarker: '+'
}

Example

import { turndown } from 'markdown-read';

const html = '<h1>Hello</h1><em>World</em>';
const options = {
  headingStyle: 'setext',
  emDelimiter: '_'
};

const markdown = turndown(html, options);
console.log(markdown);
// Output:
// Hello
// =====
//
// _World_

For a full list of available options, please refer to the Turndown Options documentation.

Advanced Features

  • Handles lazy-loaded images by setting their src attribute.
  • Extracts byline information from meta tags.
  • Supports platform-specific processing for various websites.
  • Uses Mozilla's Readability for content extraction.
  • Allows custom fetching logic through the fetcher option.