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

@katsu996/md2html

v0.0.3

Published

Convert Markdown strings and files into self-contained styled HTML documents.

Downloads

310

Readme

md2html

Markdown文字列または1つのMarkdownファイルを、既定スタイル込みの自己完結したHTML文書へ変換するTypeScriptライブラリとCLIです。生成HTMLは外部CDN、Webフォント、JavaScriptへ依存しません。

対応環境

  • Node.js >=22.18.0
  • ESM、CJS、およびES2022対応ブラウザバンドラー向けのライブラリ出力

公開パッケージ名は@katsu996/md2htmlです。公開後は次の形式で導入できます。

pnpm add @katsu996/md2html

ライブラリ

import { convertMdToHtml } from "@katsu996/md2html";

const document = convertMdToHtml("# Hello", { lang: "ja" });
document.customCss(".md2html h1 { color: red; }");

console.log(document.toString());
console.log(`${document}`);

チェーン形式も利用できます。

const html = convertMdToHtml("# Hello")
  .title("Greeting")
  .customCss(".md2html h1 { color: blue; }")
  .toString();

convertMdToHtml(markdown, options)

| option | 既定値 | 内容 | | ------------ | --------------------------- | -------------------------------------- | | title | H1またはMarkdown Document | HTMLのtitle | | lang | und | 文書言語タグ | | defaultCss | true | 既定の記事CSSを含めるか | | customCss | [] | 文字列または文字列配列の追加CSS | | rawHtml | escape | escape または allow | | gfm | true | table、取り消し線、task list等を有効化 | | breaks | false | 単一改行を<br>へ変換 |

HtmlDocumenttitle(value)lang(value)customCss(css)useDefaultCss(enabled?)を持ち、すべて同一インスタンスを返します。CSSの適用順は、ブラウザ既定 → DEFAULT_CSSoptions.customCssdocument.customCss()の呼び出し順です。

DEFAULT_CSSHtmlDocumentMd2HtmlErrorもexportされます。ライブラリで発生する安定エラーコードはINVALID_ARGUMENTINVALID_OPTIONMARKDOWN_PARSE_FAILEDHTML_BUILD_FAILEDです。

CLI

md2html <input.md | -> [options]
# input.html を入力ファイルと同じ場所へ作成
md2html input.md

# CSS、title、langを指定
md2html input.md -o output.html --css ./custom.css --title "My document" --lang ja

# stdinからstdoutへ出力
cat input.md | md2html - --stdout > output.html

| option | short | 内容 | | ---------------------- | ----------- | ------------------------------ | | --output <path> | -o | 出力HTMLファイル | | --css <path> | | UTF-8のCSSファイル。複数指定可 | | --title <text> | | HTMLタイトル | | --lang <tag> | | 文書言語 | | --no-default-css | | 既定CSSを省略 | | --allow-html | | Markdown中の生HTMLを許可 | | --stdout | | HTMLを標準出力へ出力 | | --force | -f | 既存の出力ファイルを置換 | | --help / --version | -h / -v | ヘルプ / バージョン |

stdinでは--stdoutまたは--outputが必須です。ファイル入力では出力先を省略すると、拡張子を.htmlへ変更した同じディレクトリのファイルが選ばれます。既存出力は--forceなしでは変更しません。入力Markdownまたは--cssで渡したファイルと同じ出力先は、--forceを指定しても拒否します。

安全性

  • 既定ではMarkdown中の生HTMLをHTML文字参照へエスケープします。
  • linkはhttphttpsmailtotel、相対URL、fragmentだけを許可します。imageはhttphttps、相対URLだけを許可します。
  • javascript:vbscript:data:file:および難読化されたスキームはリンク化せず、可読なテキストへ縮退します。
  • title、lang、style要素の終端文字列は文脈別に検証またはエスケープします。

--allow-htmlまたはrawHtml: "allow"は、信頼できるMarkdown専用です。このモードはHTMLをサニタイズせず、script要素、イベント属性、危険URLを含む生HTMLをそのまま許可します。信頼できない入力には使用しないでください。

開発

このリポジトリのパッケージマネージャーはpnpmです。バージョンはmise.tomlで固定されています。mise未使用の環境ではcorepackを利用できます。

pnpm install
pnpm run typecheck
pnpm run lint
pnpm test
pnpm run test:coverage
pnpm run build
pnpm pack --dry-run

pnpm run buildはtsdownがpublintとattwを統合実行するため、パッケージ検証(package:check)は不要です。