A textlint rule for checking allowed or disallowed URIs in links and images of Markdown.π₯
Click here to view the documentation for textlint-rule-allowed-uris@1.
Important
- 
Support both textlintv14 and v15. (Supports current and previous major versions oftextlint.)
- 
This rule only supports Markdown( .mdor.mdx) files. Note that it does not recognize URIs inText(.txt) files.
- 
Note that every URIs should be recognized by Markdown. URIs which are not recognized by Markdown cannot be inspected. For example, URIs without https://...orhttp://....www.google.com <www.google.com>
You can use any link or image formats which are supported by Markdown. (Even HTML tags are available!)
- 
Click to see detailed Markdown examples. Look at raw code. these all types are considered. 
- 
You can also check out the AST Tree of the above examples. 
No! This rule checks not only for URIs, but also for local paths. Below patterns are inspected too.
README.md (Relative path)
/README.md (Absolute path)
../README.md (Relative path)
/learn/start-a-new-react-project#can-i-use-react-without-a-framework (With hash)
/images/languages/javascript/composition-of-javascript/2.png?raw=true (With query parameters)
And more...Only regular expressions are allowed for URIs pattern matching. You can define the pattern you want to inspect by yourself.
Related:
allowed.links,allowed.images
Allowed URIs act like an whitelist. Only those written on the whitelist can pass through.
For example, If you pass an empty array to the option, it allows nothing. i.e. Every links or images will be detected. (For a detailed explanation, see Configs.)
Related:
disallowed.links,disallowed.images
On the contrary, disallowed URIs act like an blacklist. Only those written on the blacklist cannot pass through.
For example, If you pass an empty array to the option, it allows everything. i.e. no links or images will be detected. (For a detailed explanation, see Configs.)
npm install --save-dev textlint-rule-allowed-uris@latestyarn add --dev textlint-rule-allowed-uris@latestEvery options are optional. If you pass nothing, then nothing just happens!
{
  rules: {
    "allowed-uris": {
      allowed?: { // Optional
        links?: RegExp[], // Optional
        images?: RegExp[], // Optional
      },
      disallowed?: { // Optional
        links?: RegExp[], // Optional
        images?: RegExp[], // Optional
      },
      checkUnusedDefinitions?: boolean, // Optional
    }
  }
}You can import Options type from textlint-rule-allowed-uris package.
import type { Options } from "textlint-rule-allowed-uris";- 
allowed.links:RegExp[], Optional- 
Allowed linksact like an whitelist. Only those written on the whitelist can pass through.
- 
If you want to turn off this option, then pass nothing. NOTE: DO NOT PASS AN EMPTY ARRAY TO TURN OFF THIS OPTION. /* .textlintrc.js */ // Correct way of turning off this option. module.exports = { rules: { "allowed-uris": { allowed: { // links: [], => turned off images: [/example/], }, disallowed: { links: [/example/], images: [/example/], }, checkUnusedDefinitions: false, } } } 
- 
Default value passed: [/.*/u]
 
- 
- 
allowed.images:RegExp[], Optional- 
Allowed imagesact like an whitelist. Only those written on the whitelist can pass through.
- 
If you want to turn off this option, then pass nothing. NOTE: DO NOT PASS AN EMPTY ARRAY TO TURN OFF THIS OPTION. /* .textlintrc.js */ // Correct way of turning off this option. module.exports = { rules: { "allowed-uris": { allowed: { links: [/example/], // images: [], => turned off }, disallowed: { links: [/example/], images: [/example/], }, checkUnusedDefinitions: false, } } } 
- 
Default value passed: [/.*/u]
 
- 
- 
disallowed.links:RegExp[], Optional- 
Disallowed linksact like an blacklist. Only those written on the blacklist cannot pass through.
- 
If you want to turn off this option, then pass nothing. or here, you can pass an empty array. (because the default value passed is an empty array too.) /* .textlintrc.js */ // Correct way of turning off this option. module.exports = { rules: { "allowed-uris": { allowed: { links: [/example/], images: [/example/], }, disallowed: { // links: [], => turned off images: [/example/], }, checkUnusedDefinitions: false, } } } 
- 
Default value passed: []
 
- 
- 
disallowed.images:RegExp[], Optional- 
Disallowed imagesact like an blacklist. Only those written on the blacklist cannot pass through.
- 
If you want to turn off this option, then pass nothing. or here, you can pass an empty array. (because the default value passed is an empty array too.) /* .textlintrc.js */ // Correct way of turning off this option. module.exports = { rules: { "allowed-uris": { allowed: { links: [/example/], images: [/example/], }, disallowed: { links: [/example/], // images: [], => turned off }, checkUnusedDefinitions: false, } } } 
- 
Default value passed: []
 
- 
- 
checkUnusedDefinitions:boolean, Optional- 
If set to true, the rule will check for unused definitions and report them as problems.
- 
If set to falseor not specified, the rule will not check for unused definitions.
- 
Definitions that use //are treated as comments and always ignored.[//]: # (This behaves like a comment) 
- 
Default value passed: false
 
- 
module.exports = {
  rules: {
    "allowed-uris": {
      allowed: {
        links: [
          // regular expressions
        ],
        images: [
          // regular expressions
        ],
      },
      disallowed: {
        links: [
          // regular expressions
        ],
        images: [
          // regular expressions
        ],
      },
      checkUnusedDefinitions: true, // Optional, default is `false`
    }
  }
}textlint [options] file.md [file|dir|glob*]npx textlint --rule allowed-uris -f pretty-error file.mdnpx textlint -f pretty-error file.mdWhen configured like below:
module.exports = {
  rules: {
    "allowed-uris": {
      allowed: {
        links: [/google/],
      },
    }
  }
}Click to see sample outputs
> npx textlint src/textlint-rule-allowed-uris.md --rulesdir ./src -f pretty-error
textlint-rule-allowed-uris: allowed.links
- problem: 'mailto:[email protected]'
- allowed regular expressions: '/google/'
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md:9:1
        v
     8.
     9. [email protected]
    10.
        ^
textlint-rule-allowed-uris: allowed.links
- problem: 'mailto:[email protected]'
- allowed regular expressions: '/google/'
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md:15:1
        v
    14.
    15. <[email protected]>
    16.
        ^
textlint-rule-allowed-uris: allowed.links
- problem: ''
- allowed regular expressions: '/google/'
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md:21:1
        v
    20.
    21. [google]() <!-- empty link -->
    22.
        ^
textlint-rule-allowed-uris: allowed.links
- problem: '#heading'
- allowed regular expressions: '/google/'
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md:23:1
        v
    22.
    23. [title](#heading) <!-- hash(fragment) -->
    24.
        ^
textlint-rule-allowed-uris: allowed.links
- problem: '../README.md'
- allowed regular expressions: '/google/'
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md:25:1
        v
    24.
    25. [README.md](../README.md) <!-- relative path -->
    26.
        ^
textlint-rule-allowed-uris: allowed.links
- problem: 'https://en.wikipedia.org/wiki/File:Example.jpg'
- allowed regular expressions: '/google/'
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md:86:1
        v
    85.
    86. [](https://en.wikipedia.org/wiki/File:Example.jpg)
    87.
        ^
textlint-rule-allowed-uris: allowed.links
- problem: '/README.md'
- allowed regular expressions: '/google/'
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md:101:1
         v
    100.
    101. [linkLocal1]: /README.md "Hello README"
    102.
         ^
β 7 problems (7 errors, 0 warnings)Click to see sample outputs
> npx textlint src/textlint-rule-allowed-uris.md --rulesdir ./src -f stylish
textlint-rule-allowed-uris/src/textlint-rule-allowed-uris.md
    9:1  error  allowed.links
- problem: 'mailto:[email protected]'
- allowed regular expressions: '/google/'                    textlint-rule-allowed-uris
   15:1  error  allowed.links
- problem: 'mailto:[email protected]'
- allowed regular expressions: '/google/'                    textlint-rule-allowed-uris
   21:1  error  allowed.links
- problem: ''
- allowed regular expressions: '/google/'                    textlint-rule-allowed-uris
   23:1  error  allowed.links
- problem: '#heading'
- allowed regular expressions: '/google/'                    textlint-rule-allowed-uris
   25:1  error  allowed.links
- problem: '../README.md'
- allowed regular expressions: '/google/'                    textlint-rule-allowed-uris
   86:1  error  allowed.links
- problem: 'https://en.wikipedia.org/wiki/File:Example.jpg'
- allowed regular expressions: '/google/'                    textlint-rule-allowed-uris
  101:1  error  allowed.links
- problem: '/README.md'
- allowed regular expressions: '/google/'                    textlint-rule-allowed-uris
β 7 problems (7 errors, 0 warnings)Email links like <[email protected]> are interpreted as mailto:[email protected]. Therefore, use /^mailto:/ in regular expressions.
Thanks for having attention to this package. Issues and PRs are always welcome.π
I recommend you to read textlint guides before contributing.
And check out the Installation and Concepts of textlint-rule-allowed-uris guides below. It will help you to understand how this package works.
After that, refer to the comments in source code. It contains useful information to help you.
- 
Fork it. 
- 
Clone it to your local directory. (Git is required.) git clone https://github.com/lumirlumir/npm-textlint-rule-allowed-uris.git 
- 
Move to the npm-textlint-rule-allowed-urisdirectory.cd npm-textlint-rule-allowed-uris
- 
Install npm packages. (Node.js is required.) npm install 
- 
Edit code. 
- 
Create my-branchbranch.git switch -c my-branch 
- 
Commit your changes. ( huskyandlint-stagedwill lint and test your changed files!)git commit -am "<type>[scope]: <description>"
- 
Push them to your remote branch. 
- 
Submit a pull request. 
textlint-rule-allowed-uris rule checks allowed or disallowed URIs in links and images of Markdown.
- 
Links node type - Link(- ASTNodeTypes.Link)
- Definition(We don't use- LinkReference
- Html(- ASTNodeTypes.Html)
 
- 
Images node type - Image(- ASTNodeTypes.Image)
- Definition(We don't use- ImageReference
- Html(- ASTNodeTypes.Html)
 
Note
LinkReference, ImageReference and Definition are types parsed by @textlint/text-to-ast. But, It is not defined in @textlint/ast-node-types. (NOTE: Textlint started supporting these types since v14.5.0!)
However, you can use these three node types. It is described in textlint guides. See below.
Other plugin has defined other node type that is not defined in
@textlint/ast-node-types, but you can specify it as just a string.// A rule can treat "Example" node type export default () => { return { ["Example"](node) { // do something } }; };
In other words, you can use other node types that is not defined in @textlint/ast-node-types. like Definition type.
You can see detailed parsed AST Tree in here. (Already mentioned above.) Look which kind of types are exist for links and images.
See Code of Conduct.
See Change Log.
This project adheres to Semantic Versioning.
See Security.