refactor: simplify logic understanding

This commit is contained in:
Théo LUDWIG 2024-01-30 23:57:38 +01:00
parent cc9a1cf6a2
commit 5c39afbe20
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
3 changed files with 6 additions and 6 deletions

View File

@ -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"]
} }

View File

@ -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`,

View File

@ -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[]} */