@elasticpath/textlint-rule-no-dead-relative-link

中文文档
1.1.1发布于 2022/05/18MITCommonJS近 30 天下载 3974

Textlint rule to validate relative links(including anchor links) in markdown documents

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Options
  4. resolve-as-markdown
  5. route-map

textlint-rule-no-dead-relative-link

This is a textlint rule that validate links in markdown documents. It does the following

  • It ignores external link. The RegExp used to filter out such links is /^[a-z][a-z0-9+.-]*:/i
  • For all relative links, it checks that there is a file specified by the link. The relative links are resolved relative to the file containing the link.
  • For all relative links with anchors or just anchor within the same file, it checks that the anchor exists. It treats anchor links to markdown documents the same way as github does i.e. the rule uses github-slugger to do validation.

Installation

  • Since this is a textlint rule, first install textlint by following the textlint getting started guide.
  • This rule is available as an npm package and can be installed using
    • npm install --save-dev textlint-rule-no-dead-relative-link
      or
    • yarn add --dev textlint-rule-no-dead-relative-link and then yarn install

Usage

If you are unfamiliar with textlint then refer to configuring textlint for textlint configuration details.

Add one of the following to .textlintrc file

  • without any options
{
    "rules": {
        "no-dead-relative-link": true
    }
}

or

  • with options
{
    "rules": {
        "no-dead-relative-link": {
            "resolve-as-markdown": "[.html]"
        }
    }
}

To use it via command line arguments

textlint --rule textlint-rule-no-dead-relative-link README.md

Options

resolve-as-markdown

This option takes an array of file extension values and treats files with those extensions as if they are markdown files.

For e.g. With the following configuration

{
    "rules": {
        "no-dead-relative-link": {
            "resolve-as-markdown": [".html"]
        }
    }
}

and [README](README.html) as input, this rule will check for the existence of README.md file.

route-map

Use this option when relative links need to be validated using an alternate file path.

This option takes an array of source and destination pairs. The source value is a Regex, and the destination value is a String that can include capture groups from the source using the $ notation.

For e.g. With the following configuration

{
    "rules": {
        "no-dead-relative-link": {
            "route-map": [
                {
                    "source": "^../javadocs/(\\d+\\.\\d+\\.\\w+)", 
                    "destination": "../../static/javadocs/$1"
                }
            ]
        }
    }
}

and ../javadocs/1.0.x/overview-summary.html as the link being checked, this rule checks for the existence of the overview-summary.html file at ../../static/javadocs/1.0.x/overview-summary.html.

route-map Ordering

Ensure each route-map pair is specific because the route-map option will validate relative links using the first matching regex found in the configuration.

For e.g. With the following configuration

{
    "rules": {
        "no-dead-relative-link": {
            "route-map": [
                {
                    "source": "../../javadocs/",
                    "destination": "../website/static/javadocs/"
                },
                {
                    "source": "../javadocs/1.0.x/",
                    "destination": "../../static/javadocs/1.0.x/"
                }
            ]
        }
    }
}

and ../../javadocs/1.0.x/overview-summary.html as the link being checked, this rule checks for the existence of the overview-summary.html file at the first destination ../website/static/javadocs/1.0.x/overview-summary.html instead of the second destination ../../static/javadocs/1.0.x/overview-summary.html.

版本与发布记录

@elasticpath/textlint-rule-no-dead-relative-link 共发布 2 个版本,首次发布于 2022/04/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.1latest2022/05/184 年前
1.1.02022/04/264 年前

关于 @elasticpath/textlint-rule-no-dead-relative-link 的常见问题

@elasticpath/textlint-rule-no-dead-relative-link 是什么?

Textlint rule to validate relative links(including anchor links) in markdown documents

如何安装 @elasticpath/textlint-rule-no-dead-relative-link?

在项目目录运行 npm install @elasticpath/textlint-rule-no-dead-relative-link,或使用 pnpm add / yarn add / bun add。

@elasticpath/textlint-rule-no-dead-relative-link 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/elasticpath__textlint-rule-no-dead-relative-link 是否存在。

@elasticpath/textlint-rule-no-dead-relative-link 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@elasticpath/textlint-rule-no-dead-relative-link 需要什么版本的 Node.js?

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

@elasticpath/textlint-rule-no-dead-relative-link 可以商用吗?

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

@elasticpath/textlint-rule-no-dead-relative-link 的下载量有多少?

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

@elasticpath/textlint-rule-no-dead-relative-link 还在维护吗?

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