diff --git a/.gitignore b/.gitignore index e637f3f..de4d1f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ dist node_modules -markdownlint-rules/emd002.cjs -markdownlint-rules/emd003.cjs diff --git a/markdownlint-rules/emd004.cjs b/markdownlint-rules/emd004.cjs deleted file mode 100644 index 40947e9..0000000 --- a/markdownlint-rules/emd004.cjs +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = { - names: ['EMD004', 'no-newline-in-links'], - description: 'Newlines inside link text', - tags: ['newline', 'links'], - parser: 'markdownit', - function: function EMD004(params, onError) { - const tokens = params.parsers.markdownit.tokens.filter((token) => token.type === 'inline'); - - for (const token of tokens) { - const { children } = token; - let { lineNumber } = token; - let inLink = false; - for (const child of children) { - const { type } = child; - if (type === 'link_open') { - inLink = true; - } else if (type === 'link_close') { - inLink = false; - } else if (type === 'softbreak') { - if (inLink) { - onError({ lineNumber }); - break; - } else { - lineNumber++; - } - } - } - } - }, -}; diff --git a/markdownlint-rules/emd004.mjs b/markdownlint-rules/emd004.mjs new file mode 100644 index 0000000..36e6896 --- /dev/null +++ b/markdownlint-rules/emd004.mjs @@ -0,0 +1,31 @@ +export const names = ['EMD004', 'no-newline-in-links']; +export const description = 'Newlines inside link text'; +export const tags = ['newline', 'links']; +export const parser = 'markdownit'; + +function EMD004(params, onError) { + const tokens = params.parsers.markdownit.tokens.filter((token) => token.type === 'inline'); + + for (const token of tokens) { + const { children } = token; + let { lineNumber } = token; + let inLink = false; + for (const child of children) { + const { type } = child; + if (type === 'link_open') { + inLink = true; + } else if (type === 'link_close') { + inLink = false; + } else if (type === 'softbreak') { + if (inLink) { + onError({ lineNumber }); + break; + } else { + lineNumber++; + } + } + } + } +} + +export { EMD004 as function }; diff --git a/markdownlint-rules/index.cjs b/markdownlint-rules/index.cjs deleted file mode 100644 index 802ddb6..0000000 --- a/markdownlint-rules/index.cjs +++ /dev/null @@ -1,5 +0,0 @@ -const EMD002 = require('./emd002.cjs'); -const EMD003 = require('./emd003.cjs'); -const EMD004 = require('./emd004.cjs'); - -module.exports = [EMD002, EMD003, EMD004]; diff --git a/markdownlint-rules/index.mjs b/markdownlint-rules/index.mjs new file mode 100644 index 0000000..287c2ec --- /dev/null +++ b/markdownlint-rules/index.mjs @@ -0,0 +1,5 @@ +import * as EMD002 from './emd002.mjs'; +import * as EMD003 from './emd003.mjs'; +import * as EMD004 from './emd004.mjs'; + +export default [EMD002, EMD003, EMD004]; diff --git a/package.json b/package.json index 5eba3ba..2779799 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,7 @@ "lib": "lib" }, "scripts": { - "build": "tsc && yarn run build:emd002 && yarn run build:emd003", - "build:emd002": "esbuild --platform=node --target=node18 --format=cjs --bundle --outfile=markdownlint-rules/emd002.cjs markdownlint-rules/emd002.mjs", - "build:emd003": "esbuild --platform=node --target=node18 --format=cjs --bundle --outfile=markdownlint-rules/emd003.cjs markdownlint-rules/emd003.mjs", + "build": "tsc", "prepublishOnly": "yarn run build", "lint:eslint": "eslint \"{bin,lib,markdownlint-rules,tests}/**/*.{js,mjs,ts}\"", "lint:eslint:fix": "eslint --fix \"{bin,lib,markdownlint-rules,tests}/**/*.{js,mjs,ts}\"", @@ -54,7 +52,6 @@ "@types/glob": "^8.1.0", "@types/markdown-it": "^14.1.2", "@types/node": "22.8.7", - "esbuild": "^0.21.0", "eslint": "^8.54.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-node": "^11.1.0", diff --git a/tests/markdownlint-cli2.spec.ts b/tests/markdownlint-cli2.spec.ts index f040e1e..beacbaf 100644 --- a/tests/markdownlint-cli2.spec.ts +++ b/tests/markdownlint-cli2.spec.ts @@ -18,7 +18,7 @@ async function runMarkdownlint(args: string[], configOptions: Record