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