textlint-rule-terminology-zh

0.0.1 • Public • Published

textlint-rule-terminology-zh

textlint fixable rule npm test action

Textlint rule to check and fix terms, brands and technologies spelling in your tech writing in Chinese and English.

This rule is mainly adopted from textlint-rule-terminology and modified:

  1. Support Chinese, English and Chinese English mixed content.
  2. Slit performance improvement.

Illustration

  • Javascript → JavaScript
  • NPM → npm
  • front-end → frontend
  • website → site
  • Internet → internet

(You can customize the rules as you wish.)

Installation

npm install textlint-rule-terminology-zh

Usage

textlint --fix --rule terminology-zh Readme.md

Configuration

You can configure the rule in your .textlintrc:

{
  "rules": {
    "terminology-zh": {
      // Load default terms (see terms.jsonc in the repository)
      "defaultTerms": true,
      // Syntax elements to skip. Overrides the default
      "skip": ["Blockquote"],
      // List of terms
      "terms": [
        // Exact spelling including the case
        "JavaScript",
        "ESLint",
        "Sass",
        "Less",
        "npm",
        // RegExp (case-insensitive) → replacement
        ["front[- ]end(\\w*)", "frontend$1"],
        ["hot[- ]key", "hotkey"],
        ["repo\\b", "repository"],
        ["CLI tool(s?)", "command line tool$1"],
        ["build system(s?)", "build tool$1"],
        ["id['’]?s", "IDs"],
        ["(\\w+[^.?!]\\)? )webpack", "$1webpack"],
        ["(\\w+[^.?!]\\)? )internet", "$internet"]
        ["钱端\\s?front-end", "前端 frontend"]
      ],
      // OR load terms from a file
      "terms": "~/terms.jsonc",
      // OR load terms from npm
      "terms": "@johnsmith/terms",
      // Excludes terms
      "exclude": [
        "CSS"
      ]
    }
  }
}

Check the default terminology. Read more about configuring textlint.

{boolean} defaultTerms

Use default terms.jsonc as fallback check. Custom terms has higher priority.

{[string]} skip

Syntax elements to skip. Default element to skip is Blockquote.

Syntax elements options.skip can use:

// 'Document',       'DocumentExit',
// 'Paragraph',      'ParagraphExit',
// 'BlockQuote',     'BlockQuoteExit',
// 'ListItem',       'ListItemExit',
// 'List',           'ListExit',
// 'Header',         'HeaderExit',
// 'CodeBlock',      'CodeBlockExit',
// 'HtmlBlock',      'HtmlBlockExit',
// 'ReferenceDef',   'ReferenceDefExit',
// 'HorizontalRule', 'HorizontalRuleExit',
// 'Comment',        'CommentExit',
// 'Str',            'StrExit',
// 'Break',          'BreakExit',
// 'Emphasis',       'EmphasisExit',
// 'Strong',         'StrongExit',
// 'Html',           'HtmlExit',
// 'Link',           'LinkExit',
// 'Image',          'ImageExit',
// 'Code',           'CodeExit',
// 'Delete',         'DeleteExit'

{string|[string|[string, string]]} terms

The custom terms to check, will be merged with default terms.jsonc and has higher priority.

{string} terms

Load terms from a file or an npm repository.

Example:

{
  // Load terms from a file
  "terms": "~/terms.jsonc",
  // Load terms from npm
  "terms": "@johnsmith/terms",
}

{[string]} terms

String terms to check.

Example:

{
  "terms": ["Chinese", "前端"],
}

{[string, string]} terms

A list of reg array to check. First item of reg array is the regExpression pattern string, Second item is replacement.

Example:

{
  "terms": [
    ["钱端", "前端"],
    ["测试\\s?test", "测试 Test"]
  ],
}

{[string, string]} exclude

A list of string or reg pattern string in terms you want to ignore check.

Example:

{
  "exclude": [
    "JavaScript",
    "测试\\s?test"
  ],
}

Tips & tricks

Use textlint-filter-rule-comments to disable terminology check for particular paragraphs:

<!-- textlint-disable terminology -->

Oh my javascript!

<!-- textlint-enable -->

Other textlint rules

License

MIT License

Package Sidebar

Install

npm i textlint-rule-terminology-zh

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

20.2 kB

Total Files

5

Last publish

Collaborators

  • dujianhao