Giter Site home page Giter Site logo

remarkjs / remark-validate-links Goto Github PK

View Code? Open in Web Editor NEW
107.0 10.0 26.0 569 KB

plugin to check that Markdown links and images reference existing files and headings

Home Page: https://remark.js.org

License: MIT License

JavaScript 100.00%
remark remark-plugin markdown link valid

remark-validate-links's Introduction

remark-validate-links

Build Coverage Downloads Sponsors Backers Chat

remark plugin to check that markdown links and images point to existing local files and headings in a Git repo.

For example, this document does not have a heading named Hello. So if we’d link to it ([welcome](#hello)), we’d get a warning. Links to headings in other markdown documents (examples/foo.md#hello) and links to files (license or index.js) are also checked.

This is specifically for Git repos. Like this one. Not for say a website.

Contents

What is this?

This package is a unified (remark) plugin to check local links in a Git repo.

When should I use this?

This project is useful if you have a Git repo, such as this one, with docs in markdown and links to headings and other files, and want to check whether they’re correct. Compared to other links checkers, this project can work offline (making it fast en prone to fewer false positives), and is specifically made for local links in Git repos. This plugin does not check external URLs (see remark-lint-no-dead-urls) or undefined references (see remark-lint-no-undefined-references).

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install remark-validate-links

In Deno with esm.sh:

import remarkValidateLinks from 'https://esm.sh/remark-validate-links@13'

In browsers with esm.sh:

<script type="module">
  import remarkValidateLinks from 'https://esm.sh/remark-validate-links@13?bundle'
</script>

Use

Say we have the following file example.md in this project:

# Alpha

Links are checked:

This [exists](#alpha).
This [one does not](#apha).

# Bravo

Headings in `readme.md` are [checked](readme.md#no-such-heading).
And [missing files are reported](missing-example.js).

Definitions are also checked:

[alpha]: #alpha
[charlie]: #charlie

References w/o definitions are not checked: [delta]

…and a module example.js:

import {remark} from 'remark'
import remarkValidateLinks from 'remark-validate-links'
import {read} from 'to-vfile'
import {reporter} from 'vfile-reporter'

const file = await remark()
  .use(remarkValidateLinks)
  .process(await read('example.md'))

console.log(reporter(file))

…then running node example.js yields:

example.md
6:6-6:27   warning Cannot find heading for `#apha`; did you mean `alpha` missing-heading remark-validate-links:missing-heading
11:5-11:53 warning Cannot find file `missing-example.js`                 missing-file    remark-validate-links:missing-file
16:1-16:20 warning Cannot find heading for `#charlie`                    missing-heading remark-validate-links:missing-heading

⚠ 3 warnings

👉 Note: readme.md#no-such-heading is not warned about on the API, as it does not check headings in other markdown files. The remark CLI is able to do that.

API

This package exports no identifiers. The default export is remarkValidateLinks.

unified().use(remarkValidateLinks[, options])

Check that markdown links and images point to existing local files and headings in a Git repo.

⚠️ Important: The API in Node.js checks links to headings and files but does not check whether headings in other files exist. The API in browsers only checks links to headings in the same file. The CLI can check everything.

Parameters
  • options (Options, optional) — configuration
Returns

Transform (Transformer).

Options

Configuration (TypeScript type).

Fields
  • repository (string or false, default: detected from Git remote) — URL to hosted Git; if you’re not in a Git repository, you must pass false; if the repository resolves to something npm understands as a Git host such as GitHub, GitLab, or Bitbucket, full URLs to that host (say, https://github.com/remarkjs/remark-validate-links/readme.md#install) are checked
  • root (string, default: local Git folder) — path to Git root folder; if both root and repository are nullish, the Git root is detected; if root is not given but repository is, file.cwd is used
  • urlConfig (UrlConfig, default: detected from repo) — config on how hosted Git works; github.com, gitlab.com, or bitbucket.org work automatically; otherwise, pass urlConfig manually

UrlConfig

Hosted Git info (TypeScript type).

Fields
  • headingPrefix (string, optional, example: '#', '#markdown-header-') — prefix of headings
  • hostname (string, optional, example: 'github.com', 'bitbucket.org') — domain of URLs
  • lines (boolean, default: false) — whether lines in files can be linked
  • path (string, optional, example: '/remarkjs/remark-validate-links/blob/', '/remarkjs/remark-validate-links/src/') — path prefix before files
  • topAnchor (string, optional, example: #readme) — hash to top of readme
Notes

For this repository (remarkjs/remark-validate-links on GitHub) urlConfig looks as follows:

{
  // Domain of URLs:
  hostname: 'github.com',
  // Path prefix before files:
  prefix: '/remarkjs/remark-validate-links/blob/',
  // Prefix of headings:
  headingPrefix: '#',
  // Hash to top of markdown documents:
  topAnchor: '#readme',
  // Whether lines in files can be linked:
  lines: true
}

If this project were hosted on Bitbucket, it would be:

{
  hostname: 'bitbucket.org',
  prefix: '/remarkjs/remark-validate-links/src/',
  headingPrefix: '#markdown-header-',
  lines: false
}

Examples

Example: CLI

It’s recommended to use remark-validate-links on the CLI with remark-cli. Install both with npm:

npm install remark-cli remark-validate-links --save-dev

Let’s say we have a readme.md (this current document) and an example.md with the following text:

# Hello

Read more [whoops, this does not exist](#world).

This doesn’t exist either [whoops!](readme.md#foo).

But this does exist: [license](license).

So does this: [readme](readme.md#install).

Now, running ./node_modules/.bin/remark --use remark-validate-links . yields:

example.md
  3:11-3:48  warning  Link to unknown heading: `world`               missing-heading          remark-validate-links
  5:27-5:51  warning  Link to unknown heading in `readme.md`: `foo`  missing-heading-in-file  remark-validate-links

readme.md: no issues found

⚠ 2 warnings

Example: CLI in npm scripts

You can use remark-validate-links and remark-cli in an npm script to check and format markdown in your project. Install both with npm:

npm install remark-cli remark-validate-links --save-dev

Then, add a format script and configuration to package.json:

{
  // …
  "scripts": {
    // …
    "format": "remark . --quiet --frail --output",
    // …
  },
  "remarkConfig": {
    "plugins": [
      "remark-validate-links"
    ]
  },
  // …
}

💡 Tip: Add other tools such as prettier or ESLint to check and format other files.

💡 Tip: Run ./node_modules/.bin/remark --help for help with remark-cli.

Now you check and format markdown in your project with:

npm run format

Integration

remark-validate-links can detect anchors on nodes through several properties on nodes:

  • node.data.hProperties.name — Used by mdast-util-to-hast to create a name attribute, which anchors can link to
  • node.data.hProperties.id — Used by mdast-util-to-hast to create an id attribute, which anchors can link to
  • node.data.id — Used potentially in the future by other tools to signal unique identifiers on nodes

Types

This package is fully typed with TypeScript. It exports the additional types Options and UrlConfig.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, remark-validate-links@^13, compatible with Node.js 16.

This plugin works with unified version 6+, remark version 7+, and remark-cli version 8+.

Security

remark-validate-links, in Node, accesses the file system based on user content, and this may be dangerous. In Node git remote and git rev-parse also runs for processed files.

The tree is not modified, so there are no openings for cross-site scripting (XSS) attacks.

Related

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

remark-validate-links's People

Contributors

apetro avatar barrythepenguin avatar colliercz avatar dialex avatar greenkeeperio-bot avatar jounqin avatar kliput avatar loilo avatar murderlon avatar raipc avatar remcohaszing avatar wangshijun avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

remark-validate-links's Issues

Support linking to anchors in directories

Subject of the feature

Linking directly to folders, showing the folder's readme, is supported by all three supported Git hosts — GitHub, Gitlab and Bitbucket, and also by this plugin.

However, this plugin considers anchors appended to those directory links invalid without checking (reported as missing-heading-in-file).

Problem

Linking to a section in a folder's readme directly (without linking explicitly to the readme file) is a pattern I like to use a lot in larger projects. It works perfectly fine in GitHub and Gitlab and should therefore not be reported as an issue by this plugin. (It should theoretically work in BitBucket as well since that also renders the readme below a directory's file list. But since BitBucket behaves more like an SPA it generally has trouble with anchors in cross-folder links.)

Expected behaviour

When provided a directory link with a hash, this plugin should consider that a link to the README.md of that folder and evaluate the hash accordingly.

If no readme exists, a missing-file should be appropriate.

I added a repro at loilo/repro-remark-directory-links-49. It shows some of the described warnings but exits early due to a runtime error that occurs when linking to the root folder with a hash appended.

Caveats

  • In addition to headline anchors, the #readme anchor should be supported — however, this should already be taken care of by #48.

  • Case sensitivity is a little bit unclear: While GitHub supports uppercase and lowercase readme file names, there's no documentation on which one is preferred if more than one matching file is present.

    I tested this a while ago and if I remember correctly, there is no way to determine priority from the file name, but actually the readme file committed first will be used. GitHub will even prefer a README.rst over a README.md if it was added earlier.

    Gitlab and BitBucket also support case-insensitive readme file names, but I have no idea (and have not done any tests) how they determine the preferred file.

    However, I'd probably ignore all this "multiple readme files" fluff as "weird edge case" and hands down just pick the first thing that looks like a /^readme.md$/g.

Problem with russian characters

With the header '# Профили пользователей' and the link

[«Профили пользователей»](#профили-пользователей)

in the markdown file remark-validate-links gives an error:

5:405-5:462 warning Link to unknown heading: 'профили-пользователей'. Did you mean 'Профили-пользователей' missing-heading remark-validate-links
(capital letter)

Can you please fix it?

Nonexistent reference-style links don't cause an error

Initial checklist

Affected packages and versions

12.1.0

Link to runnable example

No response

Steps to reproduce

Run on this Markdown:

[This link doesn't go anywhere][this-is-nonexistent]

Expected behavior

The link-validating should throw an error due to this-is-nonexistent reference not existing.

Actual behavior

Validation passes without issue

Runtime

Node v17

Package manager

yarn 1

OS

macOS

Build and bundle tools

Docusaurus

Feedback: 8.0.0 major release, breaking change, changelog?

Request/feedback:

Please clarify in release notes what the breaking change is that occasions a major release.

I sunk some time into validating whether it would be okay for uPortal-app-framework to upgrade to v8. It wasn't clear from the 8.0.0 release notes why to regard the jump to 8 as a "breaking change" occasioning the major rather than minor version bump.

I think maybe arguably it was more a "minor" version bump (added a feature). Versioning is hard! 🤷‍♂️ A reasonable person could certainly adopt the stance that the plugin potentially breaking downstream builds by flagging new problems (broken image references) that it didn't previously flag amounts to a "breaking change". I can see it.

What I'd have benefited from might have been a really clear statement in the release notes of what about 8 was occasioning the bump from 7 to 8, so I could triage that breakingness as a non-issue for the downstream project.

Thanks for listening!

Error when using with Bazel

Subject of the issue

When I'm trying to run this with nodejs 10 or 12, I get this error:

Error: Cannot find module './package.json'. Please verify that the package.json has a valid "main" entry
    at Function.module.constructor._resolveFilename (/home/cristifalcas/.cache/bazel/_bazel_cristifalcas/6b39ea2a9cf0428af321c3c86d3145b0/execroot/com_etsy_search/bazel-out/k8-fastbuild/bin/apps/docserver/check_links_require_patch.js:482:17)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (apps/docserver/node_modules/remark-cli/cli.js:8:11)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Object.<anonymous> (/home/cristifalcas/.cache/bazel/_bazel_cristifalcas/6b39ea2a9cf0428af321c3c86d3145b0/execroot/com_etsy_search/bazel-out/k8-fastbuild/bin/apps/docserver/check_links_loader.js:32:24)

Your environment

  • OS: linux
  • Packages:
  • Env: node 12.13, yarn 1.13

Steps to reproduce

Tell us how to reproduce this issue. Please provide a working and simplified example.

I'm using this file for remark-cli:

const fs = require('fs');
const path = require('path');

exports.settings = {};

exports.plugins = [
  [require('remark-validate-links'), 
      {
        "repository": "https://github.etsycorp.com/Engineering/Search",
      }
  ]
];

The latest version that works of nodejs is 8.

Can you update package.json and add a "main" entry?

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Expected behaviour

What should happen?

Actual behaviour

What happens instead?

Link checker fails on a matching substring

The checker accepts links with a matching substring

We've been doing some markdown migration (moving files around). Doing this I made a (pretty bad) script for helping me change up the paths, and fix the links automatically. At some point the script spit out this:

[foobar](../../../03.Devices/chapter.md/yocto-project/bootloader-support)

This was not caught by the internal link checker (this tool), and only by our dead-link checker on the site, once it was live.

I know it is a weird case, but I'd still consider this a bug.

Your environment

  • OS: Ubuntu:18.04
  • Packages: remark-validate-links, master
  • Env: node v10.21.0

Steps to reproduce

[foobar](../thisdir/docs.md/foo/bar/baz)

`remark -u validate-links test.md

Expected behaviour

Expected the tool to fail, as this is not a valid link.

Report it as a broken link as usual

Actual behaviour

Passes due to the substring being valid (points to itself).

Fails on projects not versioned with Git

Subject of the issue

I sometimes scaffold sample projects locally without versioning them. Part of that scaffolding applies my remark-lint preset. When running npm test on those local projects, I want to ensure that my normal verification passes and remark-lint now fails when running remark-lint.

Your environment

$ node -v
v10.16.3
$ npm -v
6.9.0

Steps to reproduce

Tell us how to reproduce this issue. Please provide a working and simplified example.

  • create project that is not versioned with git
  • create a README.md
  • npm install remark-preset-lint-travi
  • remark . --frail

I'm fairly certain that this should be enough, but I'm happy to provide deeper detail if it would be more helpful.

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Sorry, versioning a reproduction would eliminate the issue

Expected behaviour

What should happen?

No error when the project is not versioned with git

Actual behaviour

What happens instead?

$ remark . --frail

README.md
  1:1  error  Error: Command failed: git remote -v
fatal: not a git repository (or any of the parent directories): .git

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Socket.stream.socket.on (internal/child_process.js:389:11)
    at Socket.emit (events.js:198:13)
    at Pipe._handle.close (net.js:606:12)

✖ 1 error

[feat] allow to setup `domain` for `repository`

Problem - we use self hosted gitlab and can't validate link like:

[foo](https://gitlab.itgalaxy.company/itgalaxy/insteria/blob/master/foo);

Problem here https://github.com/remarkjs/remark-validate-links/blob/master/index.js#L73

Using

repository: "gitlab:itgalaxy/insteria"

Return

{ type: 'gitlab',
  protocols: [ 'git+ssh', 'git+https', 'ssh', 'https' ],
  domain: 'gitlab.com',
  treepath: 'tree',
  bugstemplate: 'https://{domain}/{user}/{project}/issues',
  tarballtemplate:
   'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}',
  sshtemplate: 'git@{domain}:{user}/{project}.git{#committish}',
  sshurltemplate: 'git+ssh://git@{domain}/{user}/{project}.git{#committish}',
  browsetemplate: 'https://{domain}/{user}/{project}{/tree/committish}',
  browsefiletemplate:
   'https://{domain}/{user}/{project}/{treepath}/{committish}/{path}{#fragment}',
  docstemplate: 'https://{domain}/{user}/{project}{/tree/committish}#readme',
  httpstemplate:
   'git+https://{auth@}{domain}/{user}/{project}.git{#committish}',
  filetemplate: 'https://{domain}/{user}/{project}/raw/{committish}/{path}',
  shortcuttemplate: '{type}:{user}/{project}{#committish}',
  pathtemplate: '{user}/{project}{#committish}',
  pathmatch: /^[\/]([^\/]+)[\/]([^\/]+?)(?:[.]git|[\/])?$/,
  hashformat: [Function: formatHashFragment],
  protocols_re: /^(git\+ssh|git\+https|ssh|https):$/,
  user: 'itgalaxy',
  auth: null,
  project: 'insteria',
  committish: null,
  default: 'shortcut',
  opts: {} }

And all fine except domain, maybe we can add option to setup this? It is allow using this plugin with self hosted solution (for gitlab and github). Thanks

Support Root-Relative Links (Absolute Links)?

Hi @wooorm ! 👋

Subject of the feature

What do you think about supporting root-relative links such as in the example below?

[abc](/docs/non-existent/)
[abc](/docs/exists/#non-existent2)

I suppose this could be configured with a configuration option, maybe named like basedir.

Problem

On large sites with a lot of moving files or large directory structures, updating relative links can be a pain.

Root relative links can also avoid any ambiguity that can be caused by using the same path ending and file name between multiple files.

Expected behaviour

It would be nice for these links to also be checked.

Alternatives

gatsby-remark-check-links, but:

  1. It's Gatsby-specific
  2. It runs as a Gatsby plugin and only warns in the console :(

gh-action-check-broken-links, but:

  1. It's wrapped in a GitHub Action
  2. It assumes everything is in a pages directory

Fix support for encoded URLs

In my repo I've got paths/files with special chars (spaces, comma, etc.).
Markdown format use URL for links, which are encoded like:

[A Link](./Path%20to/File.md)

But when I use remark-validate-links, I've got the warning:

warning  Link to unknown file: `Path%20to/File.md`  missing-file  remark-validate-links

If I try to decode URLs ([A Link](./Path to/File.md)), remark parse it as a non link.
That's means it's stringified as [A Link]\(./Path to/File.md) and validate-links doesn't output any warning.

Validation features

  • log error if no link is present: [No link provided...]()
  • log error if site don't exist: [http call returns !2xx status](http://doNotExist.com)

Add support for `image`, `imageReference`

Doesn't look like it tries to validate images that are specified to be auto-expanded and rendered with the ![](image.jpg) syntax. Given that foo.jpg doesn't exist:

This doesn't show a warning:

![](image.jpg)

And this does:

[](image.jpg)

Option to ignore filename extensions

For Gatsby pages the .md is stripped off the file, so a link for a page named "src/pages/about-us.md" ends up being "/about-us/" (by default). It would be excellent to have the ability to ignore the filename extension to support link validation in Gatsby.

Links checks are failing when the header contains any special character in it.

Initial checklist

Affected packages and versions

11.0.1

Link to runnable example

No response

Steps to reproduce

Try to run the below code :

import {readSync} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import remarkValidateLinks from 'remark-validate-links'

const file = readSync('markdown/example.md')
//console.log(file);
const result = await remark()
  .use(remarkValidateLinks)
  .process(file);

console.log(reporter(result));

for markdown content

# Alpha

Links are checked:

This [exists](#alpha).
This [one does not](#bravo:-1).

# Bravo:-1

new data for bravo

Expected behavior

This should not throw any kind of validation error/warning in the console.

Actual behavior

Screen Shot 2021-10-26 at 2 52 52 PM

Runtime

Node v14

Package manager

npm v6

OS

macOS

Build and bundle tools

No response

Request: Change warnings to errors

I want to run this tool as a step of our Continuous Integration in TravisCI. Since all issues are reported as "warnings" and the exit status of the tool is 0 (success), there's no way to automatically detect an error.

I don't want to look at logs to find out there are issues. Is there any workaround?
As a quick fix you could return a non-zero exit status if there are warnings

Does not catch bad links that use absolute paths to repo root

Initial checklist

Affected packages and versions

12.1.0

Link to runnable example

No response

Steps to reproduce

I have a repo: https://github.com/eatonphil/docs-link-check-test. If you run ./remark-check.sh it will catch one bad link but not another bad link.

$ cat README.md
[link](/src/test.md)

This should fail
[link](/src/test.md#doesnt-exist)

But only this one actually fails
[link](./src/test.md#doesnt-exist)

Expected behavior

GitHub allows you to use absolute paths starting with / to mean the root directory of the repo. remark-validate-links should handle looking at the repo root to resolve these files.

Actual behavior

Root-absolute paths are not validated.

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

Some invalid references not detected

Validate links for Foliant projects

Initial checklist

Problem

I want to use remark-validate-links for linting Foliant projects, especially for those using MkDocs and CustomIDs

Remark-validate-links has a basic functionality for this task, but some features need to be added to suit my tasks:

  • slugger for parsing anchors in headings
  • possibility to verify local links according to MkDocs markdown sources structure

Do you need such functionality in this project or I just can continue my efforts in another fork?

Solution

  • add a flag for using with foliant projects
  • replace github-slugger for these projects
  • add some new conditions in find-refernces.js to verify MkDocs local links

Alternatives

I didn't think about alternatives yet

Support directories with number signs (`#`)

Subject of the feature

I'd like to validate local paths that include a "#".

Problem

An example is [src/acceptance/#smoke/apps-test.js](../src/acceptance/#smoke/apps-test.js). This of course doesn't work because the "#" is treated as a fragment. I was wondering if we could add an escape character or similar to support this? Perhaps \#smoke or %23smoke?

Alternatives

I could remove the "#" from the folder names, but they relate to an existing system that is not going to change.

Programmatic use: validate anchors in other files (like CLI)

With the CLI it is possible to validate anchor references to other files: [some link](another-file.md#some-anchor).

This is because the code path for the CLI accepts multiple files. However, the code path for programmatic use can only accept one file; as such it does not validate external anchors like the CLI.

It would be nice to be able to pass a set of files in for programmatic use. For example, my current situation looks like this:

const processor = remark().use(validateLinks);

fastGlob('{,!(.git|node_modules)/}**/*.md')
  .then(paths => Promise.all(
    paths.map(p => vfile.read(p, 'utf8'))
  ))
  .then(vfiles => Promise.all(
    vfiles.map(file => processor.process(file))
  ));

As you can see, I already have a collection of files - and I would like to validate that cross references between files are valid. Is this possible today in a way that I'm not seeing?

Add support for Pelican templates

1. Summary

It would be nice, if remark-validate-links will support Pelican templates, which have the form {variable}.

Or at least ignored them.

2. Argumentation

I use in my Markdown articles these templates:

remark-validate-links show warnings. I need to disable remark-validate-links completely, that use templates.

3. Data

  • Kira_remark-valdate-links__pelican_article_templates--non-valid_demo.md
[![KiraGoddess]({static}/KiraFolder/KiraGoddess.png)]({static}/KiraFolder/KiraGoddess.html)

4. Expected behavior

No warnings.

5. Actual behavior

D:\Kristinita>remark Kira_remark-valdate-links__pelican_article_templates--non-valid_demo.md --use remark-validate-links --no-stdout
Kira_remark-valdate-links__pelican_article_templates--non-valid_demo.md
  1:1-1:92  warning  Link to unknown file: `%7Bstatic%7D/KiraFolder/KiraGoddess.html`  missing-file                     remark-validate-links
  1:2-1:53  warning  Link to unknown file: `%7Bstatic%7D/KiraFolder/KiraGoddess.png`   missing-file                     remark-validate-links

‼ 2 warnings

Thanks.

Allow selection between warning, error and ignoring regarding the validity of links

Initial checklist

Problem

It's kinda jarring and odd to use --frail to catch warnings as errors and exit with 1. Also, other Remark warnings could cause errors if they are raised at lint time.

Solution

We should be able to specify the severity to be reported as "error", "warn" or "ignore".
Example:

{
    "plugins": {
           "validate-links": {
                     "settings": {
                          "severity": "error" // also warn or ignore
                    }
           }
    }
}

Alternatives

Another way would be to directly modify Remark itself, but I think this is much better.

Emoji headings are not supported

Subject of the issue

Describe your issue here.

I add emoji at the heading, such as ## 🧐 About, Github treat this as #-about, I try use both #about and #-about, neither of them is worked:

28:3-28:19  warning  Link to unknown heading: `-about`

Is this a bug or feature? How can I avoid ti?

This is not a place to ask questions. For that, go to discussions

Your environment

  • OS: macos
  • Packages: "remark-validate-links": "^10.0.2",
  • Env: 12

Steps to reproduce

Tell us how to reproduce this issue. Please provide a working and simplified example.

- [About](#-about)

## 🧐 About

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Expected behavior

no warning.

What should happen?

Actual behavior

warn

What happens instead?

Images in headings not slugged correctly

Subject of the issue

I found a case where a working link in github is detected as broken by remark-validate-links when the linked content has an image in it, like the badges in READMEs.

Your environment

Steps to reproduce

$ git clone https://github.com/ajoga/electricitymap-contrib.git
$ git checkout -b remark-validate-links-br
$ ./node_modules/.bin/remark --frail -u validate-links .
test.md
  106:71-106:107  warning  Link to unknown heading: `electricitymap---`  missing-heading  remark-validate-links
   108:71-108:96  warning  Link to unknown heading: `hello-`             missing-heading  remark-validate-links
   110:71-110:97  warning  Link to unknown heading: `hello2-`            missing-heading  remark-validate-links

⚠ 3 warnings

Expected behavior

These three warning should not appear. You can browse here to see that the three links are working : https://github.com/ajoga/electricitymap-contrib/blob/remark-validate-links-br/test.md

Actual behavior

We get warnings.

Backstory / use-case

I'm using remark-validate-links on the README of https://github.com/tmrowco/electricitymap-contrib

I've seen that often badges are on the line below the h1, but I guess having them in the h1 is not uncommon either, hence the report

`missing-heading-in-file` after upgrade to latest `remark-cli` (v10)

Initial checklist

Affected packages and versions

remark-cli v10.0.0, remark v14.0.0, remark-lint v8.0.0, remark-validate-links v10.0.4

Link to runnable example

https://github.com/travi-test/lerna-playground/tree/remark-heading-in-file

Steps to reproduce

  1. change into the packages/foo directory
  2. npm install
  3. npm run lint:md

the failing link does point to a real heading in a real document in the same repo:
https://github.com/travi-test/lerna-playground/blob/2efe15d21124a94d525c26d92113bcb43495467b/packages/foo/README.md#L65

Expected behavior

the heading in the referenced document exists, so it should not be an error. i added to this repo for reproduction purposes, but the private project where i first encountered this was previously not failing before the remark-cli upgrade to v10

Actual behavior

i receive the following error:

$ npm run lint:md
> @travi/[email protected] lint:md
> remark . --frail

README.md
  65:3-65:22  warning  Link to unknown heading in `../bar`: `usage`  missing-heading-in-file  remark-validate-links

⚠ 1 warning

Runtime

Node v16

Package manager

npm v7

OS

macOS

Build and bundle tools

No response

Validate external links

I'm sure you've considered the possibility of validating external links, as well as links to headings and docs. I couldn't find an explanation, though. Is this a feature you're interested in?

Fragments should be case-insensitive

Subject of the issue

remark-validate-links should authorize uppercase headings.

Currently, it authorize uppercase or mixed case link to files, but breaks for headings.

URL should be generally treated as case insensitive (cf comment).

Your environment

  • OS: MacOs
  • Packages:
    "dependencies": {
    "remark": "^10.0.1",
    "remark-cli": "^6.0.1",
    "remark-lint": "^6.0.4",
    "remark-lint-no-dead-urls": "^0.4.1",
    "remark-validate-links": "^8.0.0",
    "vuepress": ">= v1.0.0-alpha.47"
    },

Headings with inline comments are slugged incorrectly

Initial checklist

Affected packages and versions

12.1.0

Link to runnable example

No response

Steps to reproduce

Run this markdown:

# Run a container whose image is pulled from internal GitLab <!-- comment -->

[Link](#run-a-container-whose-image-is-pulled-from-internal-gitlab)

Through remark-validate-links:
remark --use remark-validate-links

Here's the same markdown to show the GitHub heading link doesn't include ----comment---- at the end:

Run a container whose image is pulled from internal GitLab

Link

Expected behavior

Shouldn't include inline comments as heading identifier. I looked at the code and it's the node toString that gets passed to the slugger, so it should probably be removed beforehand, as it's not printable, which is what the slugger docs ask to be passed.

Actual behavior

## Run a container whose image is pulled from internal GitLab <!-- comment -->

[Link](#run-a-container-whose-image-is-pulled-from-internal-gitlab)
validate-links-bug.md
  3:1-3:68  warning  Link to unknown heading: `run-a-container-whose-image-is-pulled-from-internal-gitlab`. Did you mean `run-a-container-whose-image-is-pulled-from-internal-gitlab----comment---`  missing-heading  remark-validate-links

⚠ 1 warning

Runtime

Node v16

Package manager

npm 8

OS

macOS

Build and bundle tools

Other (please specify in steps to reproduce)

There should be a way to ignore "repository" in package.json

I have the following field in my package.json:

  "repository": {
    "type": "git",
    "url": "ssh://[email protected]:7999/t2/tvui.git"
  },

When I run remark, I get the following error:

λ remark -u validate-links .

tools/tvui-tools-update-edge-scripts/README.md
  1:1  error  Error: remark-validate-links cannot parse `repository` (`ssh://[email protected]:7999/t2/tvui.git`)

That error is repeated at location 1:1 of every one of my 158 markdown files in this repo. It's a bit misleading to suggest that the error is with the markdown itself, and not with the config passed in. There should only be one error displayed to the user, before any files are checked.

But more pressingly, this issue blocks me from using this tool. I can't remove the repository field from package.json, because other tools rely on it. But if I pass a falsey value for --use 'validate-links=repository:', the code reads from the package.json anyway.

I need a flag to say something like --ignore-repository. I'm happy to just forgo repository functionality and rely only on local checking.

Thanks!

External links always report as failures

Subject of the issue

I think latest master has a problem with external links and a null git repository. My setup with v8.0.3 and the following config:

'use strict';
module.exports = {
  'settings': {
    'bullet': '*',
    'fence': '`',
    'fences': true,
    'incrementListMarker': false,
  },
  'plugins': [
    'preset-lint-recommended',
    'preset-lint-consistent',
    // 'lint-blank-lines-1-0-2', buggy
    // [
    //   'lint-code',
    //   {
    //     js: 'remark-lint-code-eslint',
    //   },
    // ],
    // 'lint-no-empty-sections',
    'lint-heading-whitespace',
    'lint-no-url-trailing-slash',
    [
      'validate-links',
      {
        // https://github.com/remarkjs/remark-validate-links/issues/28
        'repository': 'unused/unused',
      },
    ],
  ],
};

gave me no issues. When I try latest master, I get

CONTRIBUTING.md
      18:53-18:84  warning  Link to unknown file: `https:/remark.js.org`                                                                  missing-file             remark-validate-links
     19:70-19:116  warning  Link to unknown file: `https:/github.com/OSSIndex/auditjs`                                                    missing-file             remark-validate-links
    37:391-37:442  warning  Link to unknown file: `https:/code.visualstudio.com`                                                          missing-file             remark-validate-links
    41:215-41:274  warning  Link to unknown file: `https:/www.conventionalcommits.org`                                                    missing-file             remark-validate-links

I tried setting 'repository': false, as mentioned in the new README, but that didn't help.

Your environment

  • OS: MacOS
  • Packages:
    "remark-cli": "6.0.1",
    "remark-lint-heading-whitespace": "1.0.0",
    "remark-lint-no-url-trailing-slash": "3.0.1",
    "remark-preset-lint-consistent": "2.0.2",
    "remark-preset-lint-recommended": "3.0.2",
    "remark-validate-links": "remarkjs/remark-validate-links",
  • Env: node 8

Support [[wikilinks]]

Initial checklist

Problem

Trying to validate local [[wikilinks]] using remark-wiki-link and give warnings when they don't exist

Solution

It should use the link in wikilink.data.hProperties.href to check local files

Alternatives

Perhaps there's a way to transform wikilinks -> normal markdown links before using remark-validate-links. I could not find a way to do so in the wikilinks docs, and I feel this should "just work"

Or perhaps this should be done on the rehype level? I found rehype-url-inspector but it appears to be abandoned. I might make my own clone of remark-validate-links for rehype

Multiple hyphens in a row are not collapsed in headings

Multiple hyphens in a row are not collapsed in headings

Given a heading:

# step 1 - foo bar bz

[](#step-1-foo-bar-bz)

The link checker will output:

 52:1-52:60  warning  Link to unknown heading: `step-1-foo-bar-bz`. Did you mean `step-1---foo-bar-bz`  missing-heading  remark-validate-links

Which is wrong at least according to Gitlab

Where

  1. Two or more hyphens in a row are converted to one.

Which I guess means this is an error on the link-checkers part?

Your environment

  • Version: 10.0.1

Steps to reproduce

Run the checker on the file above

Custom slug generation

Could there be an option to override the slug generation algorithm by specifying a custom function? Or more specifically, the use case for me would be ignoring custom HTML/React/Vue components in headings, e.g. VuePress allows you to add custom badges which are not used in the slug.

For example ### Heading <Badge text="1.0"/> should generate a slug of heading rather than heading-badge-text10-.

How to pass `urlConfig`

Subject of the issue

Absolute link not validate in self-hosted repo

This is not a place to ask questions. For that, go to spectrum

Your environment

Steps to reproduce

  • Create test.md with content:
[foo](https://gitlab.itgalaxy.company/itgalaxy/insteria/blob/master/.editorconfigs)

Note .editorconfigs doesn't exist in repo, I specifically made a mistake in the file name, added s at end.

  • configuration:
"use strict";

module.exports = {
  plugins: [
    "remark-preset-lint-itgalaxy",
    [
      "remark-validate-links",
      {
        hostname: 'gitlab.itgalaxy.company',
        prefix: '/itgalaxy/insteria/blob/',
      }
    ]
  ]
};

  • run remark: remark . -f -q -i .gitignore

It it self-hosted gitlab, i tried debug and find what config here has

{ prefix: '',
  headingPrefix: '#',
  lines: false,
  hostname: null,
  path:
   '/home/evilebottnawi/IdeaProjects/insteria/wp-content/themes/insteria/README.md',
  base:
   '/home/evilebottnawi/IdeaProjects/insteria/wp-content/themes/insteria',
  root:
   '/home/evilebottnawi/IdeaProjects/insteria/wp-content/themes/insteria' }

value, so absolute link is skipped.

Looks my configuration is not respected, maybe remark-validate-links get output from git command and doesn't respect my configuration.

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Expected behaviour

Expected error

Actual behaviour

No error.

[foo](https://gitlab.itgalaxy.company/itgalaxy/insteria/blob/master/.editorconfigs)
README.md: no issues found

repository argument and package.json repository objects

You can pass a repository, containing anything package.jsons repository can handle.

That confused me a bit, because it can't actually handle anything package.json can handle, right? I couldn't make it work with the stringified object that I get when npm init creates a package.json, e.g.

"repository": {
    "type": "git",
    "url": "git+https://github.com/mapbox/batfish.git"
 }

What do you think would be the most clear way to explain this in the docs? Unfortunately, it doesn't look like npm clearly documents the string values possible the repository field: https://docs.npmjs.com/files/package.json#repository

Add support for HTML anchors

1. Summary

If capital letters an anchor names:

    it would be nice, if remark-validate-links will not mark it as warnings.

2. Argumentation

Capital letters in URLs is valid: URLs will be open i browsers.

I use capital letters for more readable URLs; see answer for details.

3. Data

  • Kira_remark-valdate-links__capital_letters_in_headers--non-valid_demo.md
<!-- MarkdownTOC -->

1. [Kira](#Kira)
1. [isGoddess](#isGoddess)
1. [Кира](#Кира)
1. [этоБогиня](#этоБогиня)

<!-- /MarkdownTOC -->

<a id="Kira"></a>
# Kira

<a id="isGoddess"></a>
# isGoddess

<a id="Кира"></a>
# Кира

<a id="этоБогиня"></a>
# этоБогиня

4. Expected behavior

No warnings.

5. Actual behavior

D:\SashaDebugging>remark Kira_remark-valdate-links__capital_letters_in_headers--non-valid_demo.md --use remark-validate-links --no-stdout
Kira_remark-valdate-links__capital_letters_in_headers--non-valid_demo.md
  3:4-3:17  warning  Link to unknown heading: `Kira`. Did you mean `kira`            missing-heading                  remark-validate-links
  4:4-4:27  warning  Link to unknown heading: `isGoddess`. Did you mean `isgoddess`  missing-heading                  remark-validate-links
  5:4-5:17  warning  Link to unknown heading: `Кира`. Did you mean `кира`            missing-heading                  remark-validate-links
  6:4-6:27  warning  Link to unknown heading: `этоБогиня`. Did you mean `этобогиня`  missing-heading                  remark-validate-links

‼ 5 warnings

Thanks.

No warning or error in case of missing reference

Subject of the issue

No warning or error in case of missing reference

$ remark --use validate-links <<EOF
> References and definitions are [checked][foo].
> EOF
References and definitions are [checked][foo].
<stdin>: no issues found

Your environment

  • OS: Debian 10
  • Packages:
$ npm v remark-validate-links

[email protected] | MIT | deps: 8 | versions: 22
remark plugin to validate links to headings and files
https://github.com/remarkjs/remark-validate-links#readme

keywords: unified, remark, remark-plugin, plugin, mdast, markdown, validate, link, reference, file, heading

dist
.tarball: https://registry.npmjs.org/remark-validate-links/-/remark-validate-links-10.0.0.tgz
.shasum: a76f14dc9150d9af061115adbfe3efc6e54c1424
.integrity: sha512-BLVKPCoF8BLZCgJyDNw8rEL9++ohx+lpc6eZl7GNmHxJi3SR5tA7JYNcEVmcDj7M6Kl04wmc6BaeJ1FYNQDaIQ==
.unpackedSize: 28.6 kB

dependencies:
github-slugger: ^1.0.0       mdast-util-to-string: ^1.0.0 to-vfile: ^6.0.0             unist-util-visit: ^2.0.0
hosted-git-info: ^3.0.0      propose: 0.0.5               trough: ^1.0.0               xtend: ^4.0.0

maintainers:
- johno <[email protected]>
- wooorm <[email protected]>

dist-tags:
latest: 10.0.0       next: 4.0.0-alpha.1

published a month ago by wooorm <[email protected]>

$ remark --version
remark: 12.0.0, remark-cli: 8.0.0
  • Env:
$ npm version
{ npm: '6.13.4',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.9.3',
  icu: '64.2',
  modules: '64',
  napi: '5',
  nghttp2: '1.39.2',
  node: '10.19.0',
  openssl: '1.1.1d',
  tz: '2019c',
  unicode: '12.1',
  uv: '1.28.0',
  v8: '6.8.275.32-node.55',
  zlib: '1.2.11' }

Steps to reproduce

Tell us how to reproduce this issue. Please provide a working and simplified example.

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

remark --use validate-links <<EOF
References and definitions are [checked][foo].
EOF

Expected behaviour

Issue a warning or error that the reference foo is undefined.

Actual behaviour

No warning or error.

Links are failing when the link is using any of the restricted names like "constructor"/"concat" etc.

Subject of the issue

Links with a restricted name like #constructor is failing to validate.

Describe your issue here.
If the example.md is as below:

# Test file
## Constructor
[constructor](example.md#constructor)

Validation of this fails with the below error:

(node:65188) UnhandledPromiseRejectionWarning: TypeError: hashes.push is not a function
    at addReference (...../node_modules/remark-validate-links/lib/find/find.js:121:12)
    at mark (..../node_modules/remark-validate-links/lib/find/find.js:83:11)

And the reason for it is:
in find.js

we are retrieving the hash value using

var hashes = refs[hash] || (refs[hash] = [])

And this returns a function (when hash = "constructor") - so it will not allow the next line to be executed properly.

hashes.push(node)

This line throws the above error mentioned.

Your environment

  • OS: mac
  • Packages: remark/micromark
  • Env: node > 14

Steps to reproduce

Create a markdown named : example.md with the below content

# Test file
## Constructor
[constructor](example.md#constructor)

And run usual remark -u validate-links .

Tell us how to reproduce this issue. Please provide a working and simplified example.

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Expected behavior

What should happen?

Actual behavior

What happens instead?

Problems with gitlab repository field

I am use shared remark config for github and gitlab repos.

In package.json i have:

"repository": "https://my.itgalaxy.com/user/repo/",

Output

SECURITY.md
  1:1  error  TypeError: Cannot read property 'user' of null

Seems in repo = repo ? gh(repo) : {}; gh return null , but we try to get repo.user. Can we add check on null to avoid error?

if (!repo) {
  return;
}

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.