百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

hongdown

> 数据库
开源

一个 Markdown 格式化器,强制遵循 Hong Minhee 的 Markdown 样式约定

196 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个 Markdown 格式化器,强制遵循 Hong Minhee 的 Markdown 样式约定

Hongdown

crates.io npm @hongdown/wasm GitHub Actions

Hongdown is a Markdown formatter that enforces Hong Minhee's Markdown style conventions. The formatter is implemented in Rust using the Comrak library for parsing. It produces consistently formatted Markdown output following a distinctive style used across multiple projects including Fedify, LogTape, and Optique.

Installation

Windows Package Manager

powershell
winget install HongMinhee.Hongdown

Scoop

powershell
scoop bucket add extras
scoop install hongdown

npm

bash
npm install -g hongdown

mise

bash
mise use -g aqua:dahlia/hongdown

Nix

bash
nix run github:dahlia/hongdown

Cargo

bash
cargo install hongdown

Pre-built binaries

Pre-built binaries for Linux, macOS, and Windows are available on the GitHub Releases page.

Usage

Basic usage

bash
# Format a file and print to stdout
hongdown input.md

# Format a file in place
hongdown --write input.md
hongdown -w input.md

# Format multiple files
hongdown -w *.md

# Format all Markdown files in a directory (recursive)
hongdown -w .
hongdown -w docs/

# Check if files are formatted (exit 1 if not)
hongdown --check input.md
hongdown -c input.md

# Show diff of formatting changes
hongdown --diff input.md
hongdown -d input.md

# Read from stdin (use --stdin flag or - as filename)
echo "# Hello" | hongdown --stdin
echo "# Hello" | hongdown -
hongdown --stdin  {
    if (language === "javascript" || language === "typescript") {
      return prettier.format(code, { parser: "babel" });
    }
    return null; // Keep original for other languages
  },
});

Line wrapping

  • Lines wrap at approximately 80 display columns
  • East Asian wide characters are counted as 2 columns
  • Long words that cannot be broken are preserved

Math

  • Inline ($…$) and display ($$…$$) TeX/LaTeX math is preserved verbatim, never escaped or punctuation-transformed (like code spans)
  • Inline math is kept on a single line when wrapping
  • Dollar-math parsing follows GitHub's rules, so a lone $, $ command, or $5 stays literal text
  • Disable with math = false in .hongdown.toml to treat every $ as text
markdown
The complexity is $O(n \log n)$.

$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$

MDX

MDX documents mix Markdown with JavaScript and JSX. Because the underlying CommonMark parser does not understand those constructs, formatting an MDX document normally corrupts the embedded code. MDX mode (“first, do no harm”) detects the JS/JSX constructs and passes them through verbatim, while the surrounding Markdown prose is still formatted.

Within paragraph text, the constructs Hongdown would otherwise corrupt are preserved verbatim — never escaped or punctuation-transformed:

  • ESM import/export statements, JSX elements and fragments (, , <>…), and {…} expressions (including {/* … */} comments)
  • The embedded JavaScript/JSX is preserved, not reformatted
  • Files with the .mdx extension enable MDX mode automatically; for stdin or .md input, enable it with --mdx or mdx = true in .hongdown.toml
mdx
import { Chart } from "./chart.js";

export const meta = { author: "Hong Minhee" };

A paragraph of prose is still wrapped and punctuation-transformed, while the
JSX and imports above are left exactly as written.

A JSX tag that is already valid inline HTML (for example a single {value} attribute) is left to the underlying parser, which keeps the tag while still formatting the element's Markdown children; only tags that break the HTML grammar (a {{…}} attribute, embedded quotes or spaces, or a multi-line opener) are protected as a whole.

Some constructs are intentionally left unprotected: anything inside a heading (an explicit {#id} anchor stays a heading anchor), braces inside inline code (`{x}`), math ($\frac{1}{2}$), or link/image syntax, an expression containing a regex literal whose context is ambiguous (a / immediately after }), and an ESM object whose body contains a blank line.

Links

  • External URLs are converted to reference-style links
  • References are placed at the end of each section
  • Relative/local URLs remain inline
markdown
See the [documentation] for more details.

[documentation]: https://example.com/docs

Tables

  • Pipes are aligned accounting for East Asian wide characters
  • Minimum column width is maintained

See STYLE.md for the complete style specification, including the philosophy behind these conventions and detailed formatting rules.

Editor integrations

Visual Studio Code

Install the Hongdown extension from the Visual Studio Marketplace or Open VSX Registry, then make it the default formatter for Markdown and MDX:

json
{
  "[markdown]": {
    "editor.defaultFormatter": "hongminhee.hongdown"
  },
  "[mdx]": {
    "editor.defaultFormatter": "hongminhee.hongdown"
  }
}

The extension uses a bundled WebAssembly build by default. To use a system Hongdown CLI instead:

json
{
  "hongdown.backend": "cli",
  "hongdown.cli.path": "hongdown"
}

By default, the extension looks for .hongdown.toml in the workspace root. For a standalone file outside any workspace, it falls back to the file's containing directory. Set hongdown.config.path to use a different configuration file.

Zed

Add the following to your Zed settings to use Hongdown as the Markdown formatter (contributed by Lee Dogeon):

json
{
  "languages": {
    "Markdown": {
      "formatter": {
        "external": {
          "command": "hongdown",
          "arguments": ["-"]
        }
      }
    }
  }
}

Neovim

If you use none-ls.nvim (a community-maintained fork of null-ls.nvim), you can register Hongdown as a formatter (requires none-ls-extras.nvim, contributed by Vladimir Rubin):

lua
local hongdown = require('none-ls.formatting.hongdown')
null_ls.register(hongdown)

Helix

If you use Helix, you can register Hongdown as a formatter (contributed by Jean Simard):

toml
[[language]]
name = "markdown"
auto-format = true
formatter = { command = "hongdown", args = ["--stdin"] }

Library usage

Rust

Hongdown can also be used as a Rust library:

rust
use hongdown::{format, Options};

let input = "# Hello World\nThis is a paragraph.";
let options = Options::default();
let output = format(input, &options).unwrap();
println!("{}", output);

JavaScript/TypeScript

Hongdown is available as a WebAssembly-based library for JavaScript and TypeScript:

bash
npm install @hongdown/wasm
typescript
import { format, formatWithWarnings, loadConfigFromToml } from "@hongdown/wasm";

// Basic usage
const markdown = "# Hello\nWorld";
const formatted = await format(markdown);

// With options
const result = await format(markdown, {
  lineWidth: 100,
  setextH1: false,
  fenceChar: "`",
});

// Get warnings along with formatted output
const { output, warnings } = await formatWithWarnings(markdown);
if (warnings.length > 0) {
  for (const warning of warnings) {
    console.warn(`Line ${warning.line}: ${warning.message}`);
  }
}

// Parse .hongdown.toml for WASM formatting
const { options: configOptions } = await loadConfigFromToml(configToml);
const configured = await format(markdown, configOptions);

External code block formatters configured in code_block.formatters are reported as warnings because the WASM runtime cannot execute external commands. Use the CLI for those settings.

The library works in Node.js, Bun, Deno, and web browsers. See the TypeScript type definitions for all available options.

Development

This project uses mise for task management.

Initial setup

After cloning the repository, set up the Git pre-commit hook to automatically run quality checks before each commit:

bash
mise generate git-pre-commit --task=check --write

Quality checks

The following tasks are available:

bash
# Run all quality checks
mise run check

# Individual checks
mise run check:clippy     # Run clippy linter
mise run check:fmt        # Check code formatting
mise run check:type       # Run Rust type checking
mise run check:markdown   # Check Markdown formatting

See AGENTS.md for detailed development guidelines including TDD practices, code style conventions, and commit message guidelines.

Etymology

The name Hongdown is a portmanteau of Hong (from Hong Minhee, the author) and Markdown. It also sounds like the Korean word hongdapda (홍답다), meaning “befitting of Hong” or “Hong-like.”

License

Distributed under the GPL-3.0-or-later. See LICENSE for more information.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustcommonmarkformattergfmmarkdown

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库