Giter VIP home page Giter VIP logo

check-md's Introduction

check-md

NPM version build status Test coverage David deps Known Vulnerabilities NPM download

A simple cli for checking dead links of markdown.

Usage

$ npm i check-md --save
$ npx check-md

Options

Usage: check-md [options]

Options:
  -v, --version            output the version number
  -f, --fix                Check and try to fix
  -c, --cwd [path]         Working directory of check-md, default to process.cwd()
  -r, --root [path]        Checking url root, default to ./
  -p, --preset [name]      Preset config(eg vuepress, default)
  -P, --pattern [pattern]  Glob patterns, default to **/*.md
  -i, --ignore [pattern]   Ignore patterns, will merge to pattern, default to **/node_modules
  --exit-level [level]     Process exit level, default to error, other choice is warn and none, it will not exit if setting to none
  --default-index [index]  Default index in directory, default to README.md,readme.md
  -h, --help               output usage information

configure in package.json

{
  "check-md": {
    "cwd": "./",
    "defaultIndex": [ "index.md" ],
    "exitLevel": "warn",
  }
}

Example

Running cli in directory of test.md

The result is

Checking markdown...

1 warning was found

  Should use .md instead of .html: [test6](./other.html#ctx-get-name) (/Users/Workspace/check-md/test/fixtures/docs1/test.md:15:1)


5 dead links was found

  Url link is empty: [test1]() (/Users/Workspace/check-md/test/fixtures/docs1/test.md:5:5)
  Hash is not found: [test8](/other#cccc) (/Users/Workspace/check-md/test/fixtures/docs1/test.md:19:1)
  File is not found: [test9](/123.md#cccc) (/Users/Workspace/check-md/test/fixtures/docs1/test.md:21:1)
  Hash should slugify: [test12](./other.md#ctx.get(name) (/Users/Workspace/check-md/test/fixtures/docs1/test.md:27:1)
  File is not found: [test16](./123.md#ctx.get(name) (/Users/Workspace/check-md/test/fixtures/docs1/test.md:39:1)

Executes with --fix to fix automatically

Checking failed

check-md's People

Contributors

jverhoeks avatar scbj avatar ulivz avatar v-zhzhou avatar whxaxes avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

check-md's Issues

Resolve Permalinks

When linking to other markdown files, in particular to the default README.md, it may be preferable (most of the time?) to reference them by their permalink, instead of the actual location in the directory structure. Because, if the default README.md ever changes, then the link will work; however, the content isn't exactly what it should be, so to guard against that, you want to be explicit as you can in your links.

For example, this is fine, as long as the content in /path/to/some/README.md doesn't change.

Go read the [usage docs](/path/to/some/README.md)

But, to safe guard against accidentally pointing someone to the wrong docs, it's preferred to instead to do this:

Go read the [usage docs](/path/to/some/usage-docs)

and, in the /path/to/some/README.md file, provide a permalink...

---
permalink: /path/to/some/usage-docs.html
---

This is the `/path/to/some/README.md` file, containing content for the usage docs.

But, check-md doesn't appear to account for this, and returns a dead link, even though the link isn't really dead because the permalink properly places the README.md at the permalink location.

File is not found: [usage docs](/path/to/some/usage-docs) (/Users/CDura/code/my-project/src/another/page/README.md:32:99)

Define alias directories

For example, when using webpack aliases (as suggested by vuepress docs), we have URLs for images that look like this:

![image alt](~@assets/my-image.png)

There is currently no way to declare this alias.

Slugify function for vuepress is outdated

Vuepress has updated its slugify function (for both v1 and next/v2):

const rControl = /[\u0000-\u001f]/g
const rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’–—<>,.?/]+/g
const rCombining = /[\u0300-\u036F]/g

export const slugify = (str: string): string =>
  str
    .normalize('NFKD')
    // Remove accents
    .replace(rCombining, '')
    // Remove control characters
    .replace(rControl, '')
    // Replace special characters
    .replace(rSpecial, '-')
    // Remove continuos separators
    .replace(/-{2,}/g, '-')
    // Remove prefixing and trailing separators
    .replace(/^-+|-+$/g, '')
    // ensure it doesn't start with a number (#121)
    .replace(/^(\d)/, '_$1')
    // lowercase
    .toLowerCase()

It adds steps of normalizing and removing accents, and no longer requires diacritics dependency. Also, rSpecial adds some new characters.

It's time to fix it now, but should we change defaultSlugify function directly or add a new function / config for vuepress preset?

Image resize in markdown generate dead links

I have added a sizing to my svg link and it generated a dead link error.

1 dead links was found

  File is not found: ![document structure](/document_structure.svg =573x400) (/documentation/guides/main_concepts/documents.md:6:1)

This is how the link is transformed:

'/document_structure.svg%20=573x400',

Should we pattern match % and remove what is behind ?

Strict extension mode

Strict Extension Mode

The strict extension mode makes the .md extension mandatory in links to recognized md files.

This means that a link to a markdown file not containing the .md extension will raise a warning:

Screenshot 2020-04-11 at 14 54 54

This only raises an error when the .md extension is missing on a md file. If the link is to a directory because it will automatically redirect to the README.md or index.md file inside that directory, it will NOT raise a warning.

Since dir is a directory containing a README.md file, this will NOT raise an error:

[test17](/dir)
[test18](/dir#test)

Since other is a markdown file whose .md extension is missing, this will raise an error:

[test7](/other#ctx-get-name)

[test8](/other#cccc)
Checking markdown...

2 warning was found
 
File found with this name but .md extension missing: [test7](/other#ctx-get-name) (/Users/charlottevermandel/check-md/test/fixtures/docs1/test.md:17:1)
File found with this name but .md extension missing: [test8](/other#cccc) (/Users/charlottevermandel/check-md/test/fixtures/docs1/test.md:19:1)

Usage

it is used, as --fix, by adding the option without parameter.

check-md -p 'vuepress' -c 'test/fixtures/vuepress' --strict-ext

Implementation

I'm working on it on this PR: bidoubiwa#1. I will make a PR here once it's done.

Wrong RegExp to determine the markdown links.

Step to reproduce

When the markdown file contains typescript like:

- Type: `{ [path: string]: Object }`

We'll get following error:

File is not found: [path: string]: Object }` (/path/to/foo.md:86:12)

Add option to ignore [example link](#)

There's some legit reasons that you may want to have a link that actually doesn't go anywhere in the markdown, like [example link text](#), especially in documentation sites.

In fact, you may want to be able to ignore any particular pattern in the link URL (not just ignore a particular filename pattern). For example:

Here's a [internal link](https://auth.my-project.com) that is behind Oauth, so it'll always look ☠️, but it's not 💀

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.