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 🙏

© 2026 – Pkg Stats / Ryan Hefner

news-to-markdown

v1.2.2

Published

Convert news articles to Markdown with platform-specific optimizations

Readme

news-to-markdown

Convert news articles to Markdown with platform-specific optimizations.

Features

  • 🎯 Platform-Specific Adapters: Built-in support for TouTiao, WeChat, XiaoHongShu
  • 🔌 Extensible Architecture: Easy to add custom platform adapters
  • 🚀 Three-Tier Fetch Strategy: curl → wget → Playwright (auto fallback)
  • 🧠 Dual-Engine Content Extraction: Combines Mozilla Readability + news-extractor-node
    • Readability: Complete content extraction (preserves images & multimedia)
    • NewsExtractor: Metadata extraction (title, author, publish time)
    • Smart selection of best extraction result
  • 📝 High-Quality Markdown: Powered by @siping/html-to-markdown-node

Installation

npm install news-to-markdown

Optional: Install Playwright for dynamic pages

npx playwright install chromium

Quick Start

import { NewsToMarkdownConverter } from 'news-to-markdown';

const converter = new NewsToMarkdownConverter();

const result = await converter.convert({
  url: 'https://www.toutiao.com/article/123',
});

console.log(result.markdown);

API

NewsToMarkdownConverter

convert(options: ConvertOptions): Promise<ConvertResult>

Convert a news URL to Markdown.

Options:

interface ConvertOptions {
  url: string;                    // Required: Article URL
  platform?: string;              // Optional: Force specific platform
  selector?: string;              // Optional: CSS selector for content
  noiseSelectors?: string[];      // Optional: Selectors to remove
  includeMetadata?: boolean;      // Optional: Include metadata (default: true)
  fetchStrategy?: FetchStrategy;  // Optional: 'curl' | 'wget' | 'playwright' | 'auto'
  customPlatform?: Platform;      // Optional: Custom platform adapter
  timeout?: number;               // Optional: Fetch timeout (default: 30000ms)
  verbose?: boolean;              // Optional: Enable verbose logging
}

Result:

interface ConvertResult {
  markdown: string;
  metadata: {
    title?: string;
    author?: string;
    publishTime?: string;
    platform: string;
    imageCount: number;
    contentLength: number;
    fetchMethod?: string;
    coverImage?: string;  // Recommended cover image
  };
  html?: string;  // Only if verbose: true
}

Built-in Platforms

TouTiao (头条)

  • Normalizes headings (pgc-h-* classes)
  • Handles data-src images
  • Converts bullet points to lists
  • Fixes code block spacing
const result = await converter.convert({
  url: 'https://www.toutiao.com/article/123',
  platform: 'toutiao',
});

WeChat (微信)

  • Extracts #js_content section
  • Handles data-src images
  • Removes inline styles
const result = await converter.convert({
  url: 'https://mp.weixin.qq.com/s/xxx',
  platform: 'wechat',
});

XiaoHongShu (小红书)

  • Extracts .note-content section
  • Handles data-src and data-original images
  • Removes tag elements
const result = await converter.convert({
  url: 'https://www.xiaohongshu.com/explore/xxx',
  platform: 'xiaohongshu',
});

Custom Platform Adapter

import { NewsToMarkdownConverter, BasePlatform } from 'news-to-markdown';
import { load } from 'cheerio';

class MyPlatform extends BasePlatform {
  name = 'my-platform';

  detect(url: string): boolean {
    return url.includes('mysite.com');
  }

  preprocess(html: string, url: string): string {
    const $ = load(html);
    $('.ad, .sidebar').remove();
    return $.html($('.content'));
  }

  postprocess(markdown: string): string {
    return markdown.replace(/\[AD\]/g, '');
  }
}

const converter = new NewsToMarkdownConverter();
converter.registerPlatform(new MyPlatform());

const result = await converter.convert({
  url: 'https://mysite.com/article',
});

Fetch Strategies

Auto (Default)

Tries curl → wget → Playwright in sequence until success.

const result = await converter.convert({
  url: 'https://example.com/article',
  fetchStrategy: 'auto',  // default
});

Curl

Fastest (1-3s), for static pages.

const result = await converter.convert({
  url: 'https://example.com/article',
  fetchStrategy: 'curl',
});

Wget

Fallback (2-4s), better compatibility.

const result = await converter.convert({
  url: 'https://example.com/article',
  fetchStrategy: 'wget',
});

Playwright

Slowest (5-10s), supports JavaScript rendering.

const result = await converter.convert({
  url: 'https://example.com/article',
  fetchStrategy: 'playwright',
});

Examples

See the examples directory:

  • basic.ts - Simple usage
  • platform-specific.ts - Platform-specific conversions
  • custom-platform.ts - Custom platform adapter

Architecture

news├to-markdowny)
│   └── DualExtractor (dual-engine extraction)
│       ├── Readabilit (content structure)
│       └── NewsExtractor (metadata
├── Core
│   ├── Converter (main orchestrator)
│   └── Fetcher (three-tier strategy)
├── Platforms (extensible adapters)
│   ├── TouTiao
│   ├── WeChat
│   ├── Xuzill/eaability (ctntextacti
│   ├── Generic (fallback)meadaaion)
    └── @sipng/html-to-markdown-node (HTML → Markdw
└── Dependencies
    ├── @siping/html-to-markdown-node (HTML → Markdown)
    └── news-extractor-node (content extraction)

License

MIT

Author

Ping Si [email protected]