@elythia-network/mfm

中文文档
0.1.0发布于 2026/10/13MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2368

An MFM (Misskey Flavored Markdown) parser with the API of mfm-js 0.26.0, in linear time and memory

原始使用文档

@elythia-network/mfm

A parser for MFM (Misskey Flavored Markdown) with the API of mfm-js 0.26.0: the same functions, node types and trees, in time and memory linear in the length of the input. It is the TypeScript port of the Go parser in the same repository; see the README there for the design, the work and memory limits and the shared fixtures.

npm install @elythia-network/mfm
import * as mfm from '@elythia-network/mfm';

const nodes = mfm.parse('**Hello** :wave: #mfm @[email protected]');
const simple = mfm.parseSimple('Name :custom_emoji:'); // for user names and the like
const hashtags = mfm.extract(nodes, (n) => n.type === 'hashtag');

The package is an ES module without dependencies. It needs Node.js 20 or later or a browser that supports ES2022; on Node.js versions that can require() ES modules (20.19 and 22.12 or later), require works as well.

Replacing mfm-js

Every export of mfm-js 0.26.0 is exported under the same name with the same type: parse(input, { nestLimit }), parseSimple, toString, inspect, extract, isMfmBlock, the node types (MfmNode, MfmBlock, MfmInline, MfmSimpleNode, MfmText, ... and NodeType) and the node constructors (TEXT, BOLD, N_URL, ...). Replacing the import is enough:

-import * as mfm from 'mfm-js';
+import * as mfm from '@elythia-network/mfm';

The trees are equal to mfm-js's, including the key order of the node objects, for every case of the shared fixtures and for random inputs compared with mfm-js 0.26.0 in the tests. The differences:

  1. Nest limit cap. A nestLimit above 500 is lowered to 500. Nesting is read by recursion: 1,000 levels need about 800 KB of stack before the code is optimized, close to V8's default of 984 KB, so the cap keeps a margin. The Go parser caps at 1000.

  2. Work and memory limits. One call does at most 2^21 + 32 × length units of work and keeps at most max(16 MiB, 64 × length) bytes of memo storage, where the length is in UTF-16 code units. After either runs out, the rest of the input is read as text, as described in the repository README. No input of the shared fixtures and none of the 3,000-character stress inputs in the tests reach the limits.

    The memo storage is a nominal count: it is charged with the sizes of the Go parser's structures (so that an ASCII input reaches the limit at the same point as in Go), not measured in the JavaScript heap. The heap a parse needs is larger: measured on Node.js 22 as the smallest --max-old-space-size with which the parse succeeds, the worst shape we tried (long runs of deeply nested quote blocks) needed about 330 MB for 1,048,576 characters and about 1.3 GB for 4,194,304 characters, about five times the counted amount, while 3,000-character inputs needed at most about 11 MB in total (about 4 MB more than parsing plain text). Callers that parse untrusted input should cap its length (Misskey limits a note to 3,000 characters).

Strings are handled like mfm-js: positions are UTF-16 code units, and a lone surrogate is kept as a character. nestLimit is read the way mfm-js compares it: undefined and null give 20, a fraction is rounded up, NaN and negative values act like 0.

License

MIT. The emoji pattern derives from @misskey-dev/emoji-data, and the API and the trees follow mfm-js; see THIRD_PARTY_NOTICES in the package.

版本与发布记录

@elythia-network/mfm 共发布 2 个版本,首次发布于 2026/10/13;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0latest2026/10/131 个月前
0.0.0-stage2026/10/131 个月前

关于 @elythia-network/mfm 的常见问题

@elythia-network/mfm 是什么?

An MFM (Misskey Flavored Markdown) parser with the API of mfm-js 0.26.0, in linear time and memory

如何安装 @elythia-network/mfm?

在项目目录运行 npm install @elythia-network/mfm,或使用 pnpm add / yarn add / bun add。

@elythia-network/mfm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elythia-network/mfm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@elythia-network/mfm 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@elythia-network/mfm 可以商用吗?

@elythia-network/mfm 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@elythia-network/mfm 的下载量有多少?

根据 npm 官方下载统计,@elythia-network/mfm 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,368 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elythia-network/mfm 还在维护吗?

最新版本 0.1.0 发布于 2026/10/13(1 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/10/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。