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

simple-markdown-to-html

v1.0.0

Published

A lightweight TypeScript library for converting Markdown to HTML with support for CommonMark and GitHub Flavored Markdown features

Readme

Simple Markdown to HTML

一个轻量级的 TypeScript 库,用于将 Markdown 转换为 HTML,支持 CommonMark 和 GitHub Flavored Markdown 特性。

特性

  • CommonMark 基础语法:标题、段落、粗体、斜体、链接、图片、代码块、引用、列表等
  • GitHub Flavored Markdown:表格、任务列表、删除线、自动链接等
  • HTML 标签保留:原文中的 HTML 标签会被原样保留
  • TypeScript 支持:完整的类型定义
  • 轻量级:无外部依赖,体积小巧
  • 高性能:基于正则表达式的快速解析

安装

npm install simple-markdown-to-html

或使用 yarn:

yarn add simple-markdown-to-html

或使用 pnpm:

pnpm add simple-markdown-to-html

使用方法

ES6 模块

import { md2html } from 'simple-markdown-to-html';

const markdown = `
# 标题

这是一个 **粗体** 和 *斜体* 的示例。

- 列表项 1
- 列表项 2
  - 嵌套列表

| 表头1 | 表头2 |
|-------|-------|
| 单元格1 | 单元格2 |
`;

const html = md2html(markdown);
console.log(html);

CommonJS

const { md2html } = require('simple-markdown-to-html');

const html = md2html('# Hello World\n\nThis is **bold** text.');
console.log(html);

默认导出

import md2html from 'simple-markdown-to-html';

const html = md2html('# Hello World');

支持的 Markdown 语法

基础语法

  • 标题# H1###### H6
  • 段落:普通文本段落
  • 粗体**粗体**__粗体__
  • 斜体*斜体*_斜体_
  • 粗斜体***粗斜体***___粗斜体___
  • 行内代码`代码`
  • 代码块
    ```javascript
    console.log('Hello World');
  • 链接[链接文本](URL)
  • 图片![替代文本](图片URL)
  • 引用> 引用文本
  • 无序列表- 项目* 项目+ 项目
  • 有序列表1. 项目
  • 水平分割线---***___

GitHub Flavored Markdown

  • 删除线~~删除的文本~~
  • 任务列表
    - [ ] 未完成任务
    - [x] 已完成任务
  • 表格
    | 表头1 | 表头2 |
    |-------|-------|
    | 单元格1 | 单元格2 |
  • 自动链接<https://example.com><[email protected]>

API

md2html(markdown: string): string

将 Markdown 字符串转换为 HTML 字符串。

参数:

  • markdown (string): 要转换的 Markdown 文本

返回值:

  • (string): 转换后的 HTML 文本

示例:

const html = md2html('# Hello\n\nThis is **bold**.');
// 输出: '<h1>Hello</h1>\n<p>This is <strong>bold</strong>.</p>'

注意事项

  1. HTML 标签保留:原文中的 HTML 标签会被原样保留,不会被转义
  2. 代码安全:代码块和行内代码中的 HTML 字符会被正确转义
  3. 嵌套支持:支持列表嵌套和其他复杂结构
  4. 性能优化:使用占位符机制保护代码块,避免误处理

开发

# 克隆仓库
git clone https://github.com/username/simple-markdown-to-html.git
cd simple-markdown-to-html

# 安装依赖
pnpm install

# 开发模式
pnpm run dev

# 构建
pnpm run build

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

1.0.0

  • 初始版本
  • 支持 CommonMark 基础语法
  • 支持 GitHub Flavored Markdown
  • TypeScript 支持