Skip to content

rlespinasse/textlint-rule-link-title-case

Repository files navigation

textlint-rule-link-title-case

textlint rule to enforce AP Style title case for link text and titles in Markdown documents.

Features

  • Enforces AP Style title case for link display text, titles, and references
  • Handles special terms, acronyms, and technical terminology with proper capitalization
  • Supports customization of stop words and special terms
  • Provides automatic fixing of improperly cased text

Installation

Install with npm:

npm install textlint-rule-link-title-case

Usage

Via .textlintrc (recommended):

{
  "rules": {
    "link-title-case": true
  }
}

With options:

{
  "rules": {
    "link-title-case": {
      "stopWords": ["via", "etc"],
      "specialTerms": {
        "nextjs": "Next.js",
        "nestjs": "Nest.js"
      },
      "checkLinkTitle": true,
      "checkLinkText": true
    }
  }
}

Via CLI:

textlint --rule link-title-case README.md

Options

  • checkLinkText: Boolean
    • Default: true
    • Whether to check link display text ([text](url) or [text][reference])
  • checkLinkTitle: Boolean
    • Default: true
    • Whether to check link titles ([text](url "title") or [reference]: url "title")
  • specialTerms: Object
    • Default: {}
    • Special terms with custom capitalization (e.g., {"nextjs": "Next.js"})
    • In addition of default special terms (see src/ap-style.js file)
  • stopWords: string[]
    • Default: []
    • Additional words to treat as stop words (lowercase in titles unless first/last)

Examples

Incorrect

[click here to learn about javascript](https://example.com)

[Read More About API design](https://example.com "api design principles")

[reference to github][github-link]

[github-link]: https://github.com "github homepage"

Correct

[Click Here to Learn About JavaScript](https://example.com)

[Read More About API Design](https://example.com "API Design Principles")

[Reference to GitHub][github-link]

[github-link]: https://github.com "GitHub Homepage"

Tips & tricks

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

<!-- textlint-disable link-title-case -->

[Click Here to Learn About JavaScript](https://example.com)

<!-- textlint-enable -->

AP Style Title Case Rules

This rule follows AP Style title case conventions:

  • Capitalize the first and last words
  • Capitalize all words of four letters or more
  • Capitalize nouns, pronouns, adjectives, verbs, adverbs, and subordinating conjunctions
  • Lowercase articles (a, an, the), coordinating conjunctions (and, but, or, for, nor), and prepositions of three letters or fewer
  • Capitalize a preposition of four or more letters
  • Capitalize words following hyphens, colons, em dashes, or other punctuation
  • Preserve the capitalization of proper nouns, brand names, and technical terms

Fixable

textlint-rule-link-title-case supports the --fix option.

textlint rule

See https://github.com/textlint/textlint/#fixable for more details.

Running tests

Install just and run validation tests:

$ just setup
Installing textlint globally...
✅ Project setup complete
$ just validate-all
Building project...
Running tests...
✅ Basic validation complete
Running e2e lint validation...
✅ E2E lint validation passed
Running e2e fix validation...
✅ E2E fix validation passed
✅ Full validation complete

About

Enforce AP Style title case for link text and titles in Markdown documents

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •