@diplodoc/yfmlint

中文文档
1.11.2发布于 2026/10/30MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 2310

YFM (Yandex Flavored Markdown) syntax linter with custom rules for Diplodoc platform

原始使用文档
文档目录23 节
  1. Features
  2. Installation
  3. Usage
  4. Basic Example
  5. With Plugins
  6. Configuration
  7. Documentation
  8. YFM Rules
  9. YFM001 - Inline code line length
  10. YFM002 - No header found for link
  11. YFM003 - Unreachable link
  12. YFM004 - Table not closed
  13. YFM005 - Tab list not closed
  14. YFM006 - Term definition duplicated
  15. YFM007 - Term used without definition
  16. YFM008 - Term inside definition not allowed
  17. YFM009 - Term definition not at end of file
  18. YFM010 - Unreachable autotitle anchor
  19. YFM011 - Max SVG size
  20. YFM021 - Empty automatic heading anchor
  21. YFM024 - Empty shorthand heading anchor
  22. YFM023 - Invalid visibility audience
  23. YFM025 - Missing local link anchor

english | русский


NPM version Quality Gate Status Coverage Maintainability Rating Reliability Rating Security Rating

YFM syntax linter

YFM (Yandex Flavored Markdown) syntax linter with custom rules for Diplodoc platform. Extends markdownlint with YFM-specific validation rules.

Features

  • Custom YFM rules for validating YFM-specific syntax
  • Integration with markdownlint - all standard markdownlint rules are available
  • Plugin support - integrates with plugins from @diplodoc/transform (e.g., term plugin)
  • Configurable rule levels - error, warn, info, or disabled
  • Source map support - accurate error reporting after Liquid template processing

Installation

npm install @diplodoc/yfmlint

Usage

Basic Example

import {yfmlint, log, LogLevels} from '@diplodoc/yfmlint';

const content = `# Title

[Link to missing file](./missing.md)
`;

const errors = await yfmlint(content, 'example.md', {
  lintConfig: {
    YFM003: LogLevels.ERROR, // Unreachable link
  },
});

if (errors && errors.length > 0) {
  log(errors, console);
}

With Plugins

import {yfmlint} from '@diplodoc/yfmlint';
import termPlugin from '@diplodoc/transform/plugins/term';

const errors = await yfmlint(content, path, {
  plugins: [termPlugin],
  pluginOptions: {
    // Plugin-specific options
  },
  lintConfig: {
    YFM007: true, // Term used without definition
    YFM009: 'warn', // Term definition not at end of file
  },
});

Configuration

Rules can be configured with different log levels:

const lintConfig = {
  // Boolean: true = warn, false = disabled
  YFM001: true,
  YFM002: false,

  // String: log level name
  YFM003: 'error',
  YFM004: 'warn',
  YFM005: 'info',

  // Object: full configuration
  YFM001: {
    level: 'warn',
    maximum: 120, // Custom parameter
  },
};

Documentation

For detailed information about architecture, development, and contributing, see AGENTS.md.

YFM Rules

This package extends markdownlint with custom rules for YFM syntax validation. All standard markdownlint rules are also available.

YFM001 - Inline code line length

Tags: line_length
Aliases: inline-code-length
Parameters: maximum (default: 100)

Validates that inline code spans don't exceed the maximum length. Useful for preventing overly long inline code that breaks formatting.

Example:

`this is a very long inline code that exceeds the maximum length and will trigger YFM001`

Tags: links
Aliases: no-header-found-for-link

Validates that links to headers (anchors) reference existing headers in the target file.

Example:

[Link to non-existent header](./file.md#nonexistent)

Tags: links
Aliases: unreachable-link

Validates that linked files exist and are accessible. Checks for:

  • File not found
  • File missing in table of contents
  • Both conditions

Example:

[Link to missing file](./missing.md)

YFM004 - Table not closed

Tags: table
Aliases: table-not-closed

Validates that YFM tables are properly closed. Requires the table plugin from @diplodoc/transform.

YFM005 - Tab list not closed

Tags: tab
Aliases: tab-list-not-closed

Validates that YFM tab lists are properly closed. Requires the tabs plugin from @diplodoc/transform.

YFM006 - Term definition duplicated

Tags: term
Aliases: term-definition-duplicated

Validates that term definitions are not duplicated. Requires the term plugin from @diplodoc/transform.

Example:

[term]: definition

[term]: another definition <!-- Error: duplicate definition -->

YFM007 - Term used without definition

Tags: term
Aliases: term-used-without-definition

Validates that all used terms have corresponding definitions. Requires the term plugin from @diplodoc/transform.

Example:

This uses [term] but no definition is provided.

YFM008 - Term inside definition not allowed

Tags: term
Aliases: term-inside-definition-not-allowed

Validates that term definitions don't contain other terms. Requires the term plugin from @diplodoc/transform.

YFM009 - Term definition not at end of file

Tags: term
Aliases: no-term-definition-in-content

Validates that all term definitions are placed at the end of the file. Requires the term plugin from @diplodoc/transform.

Example:

[term]: definition

Some content here <!-- Error: content after term definitions -->

[another-term]: another definition

YFM010 - Unreachable autotitle anchor

Tags: titles
Aliases: unreachable-autotitle-anchor

Validates that links to autotitle anchors reference existing titles.

Example:

[Link to non-existent title](#nonexistent-title)

YFM011 - Max SVG size

Tags: image_svg Aliases: max-svg-size

Validates that SVG images don't exceed the maximum size limit. Requires image processing plugins from @diplodoc/transform.

YFM021 - Empty automatic heading anchor

Tags: titles Aliases: empty-auto-heading-anchor

Detects headings for which the anchors plugin from @diplodoc/transform cannot generate a non-empty automatic anchor. The rule is reported as a warning by default. Add an explicit anchor to make the heading addressable.

The anchors plugin must be passed to yfmlint() for this rule to work. Diplodoc CLI and the VS Code extension already provide it.

Invalid:

## 😀

Fix:

## 😀 {#emoji-section}

YFM024 - Empty shorthand heading anchor

Tags: titles Aliases: empty-custom-heading-anchor

Warns when the shorthand ID in the final heading attribute block is empty, such as {# section-id} or {#}. Attribute-like text elsewhere does not warn. Use {#section-id} instead. Spaces around a valid entry ({ #section-id }), classes, quoted values and arbitrary boolean attributes are supported. For example, {#id hidden}, {#id data-x} and {#id custom-flag} do not warn. Bare words after the ID are parsed as boolean attributes; the rule does not guess whether the author intended a multi-word ID or remove these attributes.

The default level is WARN, not ERROR; the warning does not itself fail a build. It can be disabled or promoted through the usual lint configuration.

Rendering falls back to the automatic anchor for an empty parsed ID. Requires the anchors plugin from @diplodoc/transform 4.78.6 or later. Pass this plugin to yfmlint() to emit the YFM024 token marker. Older plugins without this marker continue to work but cannot emit this warning.

YFM023 - Invalid visibility audience

Tags: directives Aliases: invalid-visibility-audience

Validates that every visibility block selects exactly one supported audience. The rule is reported as an error by default so a typo cannot silently hide published content.

Valid:

:::visibility human
Human-only content.
:::

:::visibility agent
Agent-only content.
:::

Invalid:

:::visibility agents
This block uses an unsupported plural value.
:::

Alias: missing-local-anchor

Diplodoc CLI, the documentation builder, reports this diagnostic during HTML builds when a local link points to an existing page but its fragment does not match an anchor on that page. It checks same-page links (#section) and links to other project pages (guide.md#section), using rendered automatic and explicit anchors, including anchors from included files.

For example, [Section](guide.md#installation) produces YFM025 if guide.md is reachable but has no installation anchor. Correct the link fragment or add the anchor to the target page. Missing or unreachable target pages produce YFM003 instead.

The default level is warn, independently of YFM002. Configure the rule in the CLI project's .yfmlint file:

log-levels:
  YFM025: error # warn to report a warning, disabled to disable the check

For the data flow and the responsibilities of the builder, plugins, and lint rules, see Where checks run.

版本与发布记录

@diplodoc/yfmlint 共发布 38 个版本,首次发布于 2025/03/11;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.11.2latest2026/10/3014 天前
1.11.12026/10/2816 天前
1.11.02026/10/1430 天前
1.10.02026/09/161 个月前
1.9.42026/08/282 个月前
1.9.32026/08/272 个月前

其他发布通道:merge-includes-step0 → 0.0.0-rc-merge-includes-step0-23293592321。

关于 @diplodoc/yfmlint 的常见问题

@diplodoc/yfmlint 是什么?

YFM (Yandex Flavored Markdown) syntax linter with custom rules for Diplodoc platform

如何安装 @diplodoc/yfmlint?

在项目目录运行 npm install @diplodoc/yfmlint,或使用 pnpm add / yarn add / bun add。

@diplodoc/yfmlint 支持 TypeScript 吗?

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

@diplodoc/yfmlint 支持 ESM 还是 CommonJS?

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

@diplodoc/yfmlint 可以商用吗?

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

@diplodoc/yfmlint 的下载量有多少?

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

@diplodoc/yfmlint 还在维护吗?

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