Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

markdownlint-rule-relative-links

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdownlint-rule-relative-links - npm Package Compare versions

Comparing version 2.1.2 to 2.1.3

17

package.json
{
"name": "markdownlint-rule-relative-links",
"version": "2.1.2",
"version": "2.1.3",
"public": true,

@@ -38,4 +38,5 @@ "description": "Custom rule for markdownlint to validate relative links.",

"lint:prettier": "prettier . --check --ignore-path .gitignore",
"lint:javascript": "tsc --project jsconfig.json --noEmit",
"lint:staged": "lint-staged",
"test": "node --test ./test",
"test": "node --test --experimental-test-coverage ./test",
"release": "semantic-release",

@@ -50,5 +51,6 @@ "_postinstall": "husky install",

"devDependencies": {
"@commitlint/cli": "18.4.3",
"@commitlint/config-conventional": "18.4.3",
"@types/node": "20.10.5",
"@commitlint/cli": "18.4.4",
"@commitlint/config-conventional": "18.4.4",
"@types/markdown-it": "13.0.7",
"@types/node": "20.10.8",
"editorconfig-checker": "5.1.2",

@@ -64,8 +66,9 @@ "eslint": "8.56.0",

"lint-staged": "15.2.0",
"markdownlint": "0.32.1",
"markdownlint": "0.33.0",
"markdownlint-cli2": "0.11.0",
"pinst": "3.0.0",
"prettier": "3.1.1",
"semantic-release": "22.0.12"
"semantic-release": "22.0.12",
"typescript": "5.3.3"
}
}

@@ -46,5 +46,18 @@ <h1 align="center">markdownlint-rule-relative-links</h1>

```sh
awesome.md:3 relative-links Relative links should be valid [Link "./invalid.txt" should exist in the file system]
awesome.md:3 relative-links Relative links should be valid ["./invalid.txt" should exist in the file system]
```
### Additional features
- Support images (e.g: `![Image](./image.png)`).
- Support anchors (heading fragment links) (e.g: `[Link](./awesome.md#existing-heading)`).
- Ignore external links and absolute paths as it only checks relative links (e.g: `https://example.com/` or `/absolute/path.png`).
### Limitations
- Only images and links defined using markdown syntax are supported, html syntax is not supported (e.g: `<a href="./link.txt" />` or `<img src="./image.png" />`).
- Anchors checking is limited to headings, other elements are not supported (e.g: with a "id", `<div id="anchor" />`).
Contributions are welcome to improve the rule, and to alleviate these limitations. See [CONTRIBUTING.md](./CONTRIBUTING.md) for more information.
### Related links

@@ -51,0 +64,0 @@

@@ -8,3 +8,2 @@ "use strict"

filterTokens,
addError,
convertHeadingToHTMLFragment,

@@ -14,2 +13,7 @@ getMarkdownHeadings,

/** @typedef {import('markdownlint').Rule} MarkdownLintRule */
/**
* @type {MarkdownLintRule}
*/
const customRule = {

@@ -21,7 +25,8 @@ names: ["relative-links"],

filterTokens(params, "inline", (token) => {
for (const child of token.children) {
const { lineNumber, type, attrs } = child
const children = token.children ?? []
for (const child of children) {
const { type, attrs, lineNumber } = child
/** @type {string | null} */
let hrefSrc = null
/** @type {string | undefined} */
let hrefSrc

@@ -51,10 +56,9 @@ if (type === "link_open") {

if (isRelative) {
const detail = `Link "${hrefSrc}"`
const detail = `"${hrefSrc}"`
if (!fs.existsSync(url)) {
addError(
onError,
onError({
lineNumber,
`${detail} should exist in the file system`,
)
detail: `${detail} should exist in the file system`,
})
continue

@@ -81,7 +85,6 @@ }

if (!headingsHTMLFragments.includes(url.hash)) {
addError(
onError,
onError({
lineNumber,
`${detail} should have a valid fragment`,
)
detail: `${detail} should have a valid fragment identifier`,
})
}

@@ -88,0 +91,0 @@ }

const MarkdownIt = require("markdown-it")
/** @typedef {import('markdownlint').RuleParams} MarkdownLintRuleParams */
/** @typedef {import('markdownlint').MarkdownItToken} MarkdownItToken */
/**
* Calls the provided function for each matching token.
*
* @param {object} params RuleParams instance.
* @param {MarkdownLintRuleParams} params RuleParams instance.
* @param {string} type Token type identifier.
* @param {Function} handler Callback function.
* @param {(token: MarkdownItToken) => void} handler Callback function.
* @returns {void}

@@ -20,23 +23,2 @@ */

/**
* Adds a generic error object via the onError callback.
*
* @param {object} onError RuleOnError instance.
* @param {number} lineNumber Line number.
* @param {string} [detail] Error details.
* @param {string} [context] Error context.
* @param {number[]} [range] Column and length of error.
* @param {object} [fixInfo] RuleOnErrorFixInfo instance.
* @returns {void}
*/
const addError = (onError, lineNumber, detail, context, range, fixInfo) => {
onError({
lineNumber,
detail,
context,
range,
fixInfo,
})
}
/**
* Converts a Markdown heading into an HTML fragment according to the rules

@@ -102,4 +84,6 @@ * used by GitHub.

const children = token.children ?? []
headings.push(
`${token.children
`${children
.map((token) => {

@@ -117,5 +101,4 @@ return token.content

filterTokens,
addError,
convertHeadingToHTMLFragment,
getMarkdownHeadings,
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc