mirror of
				https://github.com/theoludwig/markdownlint-rule-relative-links.git
				synced 2025-09-09 19:39:29 +02:00 
			
		
		
		
	refactor: simplify logic understanding
This commit is contained in:
		| @@ -66,7 +66,7 @@ Contributions are welcome to improve the rule, and to alleviate these limitation | ||||
|  | ||||
| ## Prerequisites | ||||
|  | ||||
| - [Node.js](https://nodejs.org/) >= 16.0.0 | ||||
| [Node.js](https://nodejs.org/) >= 16.0.0 | ||||
|  | ||||
| ## Installation | ||||
|  | ||||
| @@ -88,7 +88,7 @@ We recommend configuring [markdownlint-cli2](https://github.com/DavidAnson/markd | ||||
|     "default": true, | ||||
|     "relative-links": true | ||||
|   }, | ||||
|   "globs": ["**/*.{md,mdx}"], | ||||
|   "globs": ["**/*.md"], | ||||
|   "ignores": ["**/node_modules"], | ||||
|   "customRules": ["markdownlint-rule-relative-links"] | ||||
| } | ||||
|   | ||||
| @@ -72,7 +72,7 @@ const customRule = { | ||||
|  | ||||
|         if (url.hash.length <= 0) { | ||||
|           if (hrefSrc.includes("#")) { | ||||
|             if (type !== "link_open") { | ||||
|             if (type === "image") { | ||||
|               onError({ | ||||
|                 lineNumber, | ||||
|                 detail: `${detail} should not have a fragment identifier as it is an image`, | ||||
| @@ -89,7 +89,7 @@ const customRule = { | ||||
|           continue | ||||
|         } | ||||
|  | ||||
|         if (type !== "link_open") { | ||||
|         if (type === "image") { | ||||
|           onError({ | ||||
|             lineNumber, | ||||
|             detail: `${detail} should not have a fragment identifier as it is an image`, | ||||
|   | ||||
| @@ -2,6 +2,8 @@ const MarkdownIt = require("markdown-it") | ||||
|  | ||||
| const { getHtmlAttributeRe } = require("./markdownlint-rule-helpers/helpers.js") | ||||
|  | ||||
| const markdownIt = new MarkdownIt({ html: true }) | ||||
|  | ||||
| /** | ||||
|  * Converts a Markdown heading into an HTML fragment according to the rules | ||||
|  * used by GitHub. | ||||
| @@ -37,7 +39,6 @@ const ignoredTokens = new Set(["heading_open", "heading_close"]) | ||||
|  * @returns {string[]} | ||||
|  */ | ||||
| const getMarkdownHeadings = (content) => { | ||||
|   const markdownIt = new MarkdownIt({ html: true }) | ||||
|   const tokens = markdownIt.parse(content, {}) | ||||
|  | ||||
|   /** @type {string[]} */ | ||||
| @@ -86,7 +87,6 @@ const idHTMLAttributeRegex = getHtmlAttributeRe("id") | ||||
|  * @returns {string[]} | ||||
|  */ | ||||
| const getMarkdownIdOrAnchorNameFragments = (content) => { | ||||
|   const markdownIt = new MarkdownIt({ html: true }) | ||||
|   const tokens = markdownIt.parse(content, {}) | ||||
|  | ||||
|   /** @type {string[]} */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user