Code Monkey home page Code Monkey logo

textlint-rule-no-dead-relative-link's Introduction

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 @elasticpath/textlint-rule-no-dead-relative-link
      or
    • yarn add --dev @elasticpath/textlint-rule-no-dead-relative-link

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": {
        "@elasticpath/no-dead-relative-link": true
    }
}

or with options:

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

To use it via command line arguments

textlint --rule @elasticpath/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": {
        "@elasticpath/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": {
        "@elasticpath/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": {
        "@elasticpath/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.

textlint-rule-no-dead-relative-link's People

Contributors

donganzh avatar ep-linden avatar long-wan-ep avatar pa-eps avatar parthpp avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

textlint-rule-no-dead-relative-link's Issues

Broken links inside markdown blockquote should be reported as error

Currently this rule does not report an error if there is a broken link within a text that is inside a markdown blockquote. For example:

    > If these property values do not exist in the settings.xml, the source code might not be following the guidelines at [Setup Guide](../setup-introduction.md).

The relative link in the above sample could be broken but the linter rule does not report it as an error. If I remove the blockquote (>) and write it as regular paragraph, then the broken link gets reported as error.

Absolute link should be ignored

I'm using version 1.0.2 and using the following configuration.

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

I have snippets of markdown that looks like below where I have a link that is not "external" but it's not relative either. It's an absolute link for the site.

For the latest compatibility matrix, see the [Compatibility Matrix](/path/to/compatibility.html).

This is being reported as invalid link because the linter is looking for a corresponding compatibility.md file because of my existing configuration. Should this be ignored since it's technically an "absolute" link.

Deprecated dependency on version `7.4.4` of `@babel/polyfill`

Hello,

I'm running this rule on a fresh setup and got the following warning about a deprecated dependency.

yarn install v1.13.0
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
warning textlint-rule-no-dead-relative-link > @babel/[email protected]: 🚨 As of Babel 7.4.0, this
package has been deprecated in favor of directly
including core-js/stable (to polyfill ECMAScript
features) and regenerator-runtime/runtime
(needed to use transpiled generator functions):

  > import "core-js/stable";
  > import "regenerator-runtime/runtime";
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "markdown-spellcheck > [email protected]" has unmet peer dependency "sinon@1".
[4/4] Building fresh packages...
success Saved lockfile.
Done in 22.19s.

Feature: ignore relative link that matches a given pattern

Hello - I recently came across a scenario where certain relative links needs to be ignored. This is because when the linter runs, some files are not available where the relative link points to. Those files will be available during runtime. That's why the relative link check on those files fails.

I'd like to propose an option where we can configure an array of regex patterns. The linter will then ignore any links that matches one of the patterns.

Anchor link is reported as broken even though it's not broken

I have a heading with a special character (apostrophe) like this:

## Connecting to Application’s JVM

Some content goes here

I have a relative link to the above section that works in my rendering tool. The anchor link is written as:

For more information, see [Connecting to the Applications JVM’s](#connecting-to-application-s-jvm)

The above line is reported as containing broken anchor link even though it's not broken.

The rule should not report error for email address

This rule is currently reporting email address as an invalid relative link.

Here's my markdown sample:

Send an email to [our support team](mailto:[email protected]) to request access.

This produces the following error:

  64:48  error    mailto:[email protected] is dead. (only http(s) protocols are supported)  no-dead-link

I think the rule should ignore email addresses instead of blocking it since this rule is not responsible for validating email addresses.

The rule is not working in Windows platform

I have a markdown file with following snippet:

You may now proceed to setup the login server as described [here](./login-server.html).

It's a relative link to another file named login-server.md. On my mac device, the rule is working properly and does not report any errors. But, on my colleague's Windows machine, it's incorrectly reporting that line as an error. I tried to change the markdown snippet in different ways like so:

You may now proceed to setup the login server as described [here](./login-server.md).
You may now proceed to setup the login server as described [here](login-server.html).
You may now proceed to setup the login server as described [here](login-server.md).

None of that seems to work on the Windows platform.

Does not report invalid relative links when invalid routing rules are provided

Test Steps
Provide routing rules with regex that do not match any of the invalid relative links in the config file. Then run textlint-rule-no-dead-relative-link.

Expected Results
See report from textlint-rule-no-dead-relative-link stating that the relative link is invalid.

Actual Results
The report is empty with no invalid relative links.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.