remarkjs / remark-lint-no-dead-urls

lint rule to warn when URLs are dead
https://unifiedjs.com
MIT License
78 stars 13 forks source link

Fails on Live URL #24

Closed karlhorky closed 4 years ago

karlhorky commented 4 years ago

Hi @davidtheclark, thanks for this library!

When I run this with the following MDX content...

<a
  href="https://www.freecodecamp.org/news/a-beginners-guide-to-graphql-86f849ce1bec/"
  target="_blank"
>
  freeCodeCamp: A Beginner’s Guide to GraphQL
</a>

...it fails as in the error message below:

$ yarn remark index.md
index.md
  2:9-2:86  warning  Link to https://www.freecodecamp.org/news/a-beginners-guide-to-graphql-86f849ce1bec/" is dead  no-dead-urls  remark-lint

⚠ 1 warning

remark-lint-no-dead-urls appears to be taking the " at the end along with the link.

cc @wooorm

karlhorky commented 4 years ago

Ahh, sorry, just realized that this is an incompatibility between Markdown and MDX.

Markdown does not allow for that syntax (at least on https://markdownlivepreview.com/):

Screen Shot 2020-08-13 at 15 24 25

I guess that it wouldn't make sense for remark to support this.

I will see what I can do with gotOptions or something...

Closing.

wooorm commented 4 years ago

Ah yeah, HTML like this is not supported by Markdown. See CommonMark. So the URL, in GFM, is seen as an actual URL.

If you want to ignore MDX, you can use the remark-mdx plugin. Although it won’t check href props

karlhorky commented 4 years ago

Right, thanks for the explanation 👍

I'm looking to lint all of my .mdx files for broken links, don't have any .md files at the moment...

Hm, maybe eslint-mdx will be helpful.

Edit: ah, maybe not: https://github.com/mdx-js/eslint-mdx/issues/203

karlhorky commented 4 years ago

Hmm... I guess I'll use patch-package to remove the " from the end of node.url. 😅

wooorm commented 4 years ago

why not use remark-mdx?

karlhorky commented 4 years ago

Hm, maybe I misunderstood your comment above:

If you want to ignore MDX, you can use the remark-mdx plugin. Although it won’t check href props

I don't want to ignore MDX - I want to check it :)

karlhorky commented 4 years ago

Looking at remark-mdx, can't tell - does it work with remark-lint and remark-cli?

Edit: I guess it does - my package.json:

{
  "remarkConfig": {
    "plugins": [
      "remark-mdx",
      "remark-lint-no-dead-urls"
    ]
  }
}
wooorm commented 4 years ago

I don't want to ignore MDX - I want to check it :)

Well, this plugin works on markdown syntax. remark-mdx makes sure MDX is understood, but it’s still a different syntax that isn’t markdown. I don’t think there exists a project like remark-lint-no-dead-links for MDX. Would <Icon src="..."> also be checked? Etc., many new problems!

karlhorky commented 4 years ago

Ah, understood. So the links in format of <a href=""></a> are not recognized as a link with a node.url by remark-mdx, I suppose...

wooorm commented 4 years ago

That is correct, remark/markdown does not understand HTML. And while MDX understands JSX, it does not map JSX to “equivalents” in Markdown.