@flowershow/remark-wiki-link

中文文档
4.0.1发布于 2026/10/26MITTypeScriptESM + CJS构建来源已验证近 30 天下载 5.2万

Parse and render wiki-style links, especially Obsidian style links.

原始使用文档
文档目录14 节
  1. Features supported
  2. Installation
  3. Usage
  4. Configuration options
  5. format
  6. files
  7. permalinks
  8. className
  9. newClassName
  10. urlResolver
  11. aliasDivider
  12. Generating list of files
  13. Using with Obsidian permalinks
  14. Running tests

remark-wiki-link

remark plugin to parse and render wiki-style links like [[...]] and ![[...]] in markdown. This works whatever markdown you have and it is particularly designed to support the Obsidian style links.

Features supported

  • Support [[Internal link]]
  • Support [[Internal link|With custom text]]
  • Support [[Internal link#heading]]
  • Support [[Internal link#heading|With custom text]]
  • Support ![[Image.png]] (images with optional dimensions: ![[image.jpg|200x300]])
  • Support ![[Video.mp4]] (videos with optional dimensions: ![[video.mp4|640x480]])
  • Support ![[Audio.mp3]]
  • Support ![[Document.pdf]]

Future support:

  • Support ![[Embed note]]
  • Support ![[Embed note#heading]]

Installation

npm install @flowershow/remark-wiki-link

Usage

import { unified } from "unified";
import remarkParse from "remark-parse";
import wikiLinkPlugin from "@flowershow/remark-wiki-link";

const processor = unified().use(remarkParse).use(wikiLinkPlugin);

Configuration options

format

Type: "regular" | "shortestPossible" Default: "shortestPossible"

Controls how wiki link targets are matched against files:

  • "regular": Exact path matching. The wiki link target must match the file path exactly (excluding extension).
    • Example: [[blog/my-post]] will only match blog/my-post.md
  • "shortestPossible": Obsidian-style matching. The wiki link target is matched against the end of file paths, and the shortest matching path is used.
    • Example: [[my-post]] can match both blog/my-post.md and docs/my-post.md, but will resolve to whichever has the shorter path
    • This allows you to use short wiki links like [[my-post]] instead of full paths like [[blog/my-post]]

files

Type: Array<string> Default: []

A list of file paths used to match wikilinks. Supports both .md and .mdx files. Wikilinks without a matching file will have the new class.

(When using format: "shortestPossible", this list is used to resolve shortened paths to their full paths.)

Type: Record<string, string> Default: {}

A map of file paths to their custom permalinks (e.g. { "path/to/file.md": "/custom-permalink" }). When a wikilink matches a file that has a permalink defined, the permalink will be used instead of the urlResolver. This is useful for Obsidian-style permalink support where you want specific URLs for certain files.

Example:

const processor = unified()
  .use(remarkParse)
  .use(wikiLinkPlugin, {
    files: ["blog/my-post.md", "docs/guide.md"],
    permalinks: {
      "blog/my-post.md": "/blog/custom-url",
      "docs/guide.md": "/documentation/guide",
    },
  });

With this configuration:

  • [[blog/my-post]] will link to /blog/custom-url
  • [[blog/my-post#heading]] will link to /blog/custom-url#heading
  • [[docs/guide]] will link to /documentation/guide

className

Type: string Default: "internal"

Class name added to all wiki link and embed nodes.

newClassName

Type: string Default: "new"

Class name added to nodes for which no matching permalink (passed in permalinks option) was found.

urlResolver

Type: (name: string) => string Default: (name: string) => name

A function that resolves a wikilink (or embed) target to a URL path. The target is the part in [[target|alias]] or ![[target]].

aliasDivider

Type: string Default: "|"

The character used to separate the link target from its alias in wiki links during both parsing and stringification. For example, in [[target|alias]], the divider is |.

This option allows you to use different wiki link syntaxes. For instance, you can use : as a divider by setting aliasDivider: ":", which would parse and stringify links as [[target:alias]].

Generating list of files

If you're using shortest possible path format for your wiki links, you need to set option.format: "shortestPossible" and provide the plugin with a list of files in your content folder as option.files. You can generate this list using your own script or use a file system utility like glob:

import { unified } from "unified";
import remarkParse from "remark-parse";
import wikiLinkPlugin from "@flowershow/remark-wiki-link";
import glob from "glob";

// Get all markdown files (both .md and .mdx)
const files = glob.sync("**/*.{md,mdx}", { cwd: "content" });

const processor = unified().use(remarkParse).use(wikiLinkPlugin, {
  format: "shortestPossible",
  files,
});

If you're using Obsidian and want to map specific files to custom URLs (permalinks), you can use the permalinks option:

import { unified } from "unified";
import remarkParse from "remark-parse";
import wikiLinkPlugin from "@flowershow/remark-wiki-link";
import glob from "glob";

// Get all markdown files (both .md and .mdx)
const files = glob.sync("**/*.{md,mdx}", { cwd: "content" });

// Create a map of file paths to their custom permalinks
const permalinks = {
  "blog/2024/my-post.md": "/blog/my-custom-url",
  "docs/getting-started.md": "/docs/start",
  // ... more mappings
};

const processor = unified().use(remarkParse).use(wikiLinkPlugin, {
  format: "shortestPossible",
  files,
  permalinks,
});

Running tests

npm test

版本与发布记录

@flowershow/remark-wiki-link 共发布 24 个版本,首次发布于 2022/12/21;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.1latest2026/10/2621 天前
4.0.02026/06/244 个月前
3.4.02026/02/188 个月前
3.3.12025/12/0811 个月前
3.3.02025/12/0811 个月前
3.2.12025/11/2011 个月前

关于 @flowershow/remark-wiki-link 的常见问题

@flowershow/remark-wiki-link 是什么?

Parse and render wiki-style links, especially Obsidian style links.

如何安装 @flowershow/remark-wiki-link?

在项目目录运行 npm install @flowershow/remark-wiki-link,或使用 pnpm add / yarn add / bun add。

@flowershow/remark-wiki-link 支持 TypeScript 吗?

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

@flowershow/remark-wiki-link 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flowershow/remark-wiki-link 可以商用吗?

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

@flowershow/remark-wiki-link 的下载量有多少?

根据 npm 官方下载统计,@flowershow/remark-wiki-link 在 2026/10/15 – 2026/11/13 这 30 天内被下载 52,085 次,日均约 1,736 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flowershow/remark-wiki-link 还在维护吗?

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