mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add content parsing via micromark, publish frozen micromark tokens alongside markdown-it tokens, remove assert from micromark wrapper.
This commit is contained in:
parent
ed854f7092
commit
1461ad6272
7 changed files with 3955 additions and 32 deletions
2
.github/workflows/test-repos.yml
vendored
2
.github/workflows/test-repos.yml
vendored
|
@ -25,6 +25,8 @@ jobs:
|
|||
run: npm install --no-package-lock
|
||||
- name: Clone Test Repos
|
||||
run: npm run clone-test-repos
|
||||
- name: Build markdownlint-micromark
|
||||
run: npm run build-micromark
|
||||
- name: Lint Test Repos
|
||||
run: npm run lint-test-repos
|
||||
- name: Run Extra Tests
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,8 @@
|
|||
coverage
|
||||
demo/markdown-it.min.js
|
||||
demo/markdownlint-browser.min.js
|
||||
micromark/micromark.cjs
|
||||
micromark/micromark.dev.cjs
|
||||
node_modules
|
||||
!test/node_modules
|
||||
npm-debug.log
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,7 +4,8 @@
|
|||
|
||||
const path = require("node:path");
|
||||
const { promisify } = require("node:util");
|
||||
const markdownIt = require("markdown-it");
|
||||
const markdownit = require("markdown-it");
|
||||
const micromark = require("./micromark.cjs");
|
||||
const { deprecatedRuleNames } = require("./constants");
|
||||
const rules = require("./rules");
|
||||
const helpers = require("../helpers");
|
||||
|
@ -549,16 +550,23 @@ function lintContent(
|
|||
configParsers,
|
||||
mapAliasToRuleNames(ruleList)
|
||||
);
|
||||
// Hide the content of HTML comments from rules, etc.
|
||||
// Parse content into parser tokens
|
||||
const markdownitTokens = md.parse(content, {});
|
||||
const micromarkTokens = micromark.parse(content);
|
||||
// Hide the content of HTML comments from rules
|
||||
content = helpers.clearHtmlCommentText(content);
|
||||
// Parse content into tokens and lines
|
||||
const tokens = md.parse(content, {});
|
||||
// Parse content into lines and update markdown-it tokens
|
||||
const lines = content.split(helpers.newLineRe);
|
||||
annotateAndFreezeTokens(tokens, lines);
|
||||
annotateAndFreezeTokens(markdownitTokens, lines);
|
||||
// Create (frozen) parameters for rules
|
||||
const parsers = Object.freeze({
|
||||
"markdownit": markdownitTokens,
|
||||
"micromark": micromarkTokens
|
||||
});
|
||||
const paramsBase = {
|
||||
name,
|
||||
tokens,
|
||||
parsers,
|
||||
"tokens": markdownitTokens,
|
||||
"lines": Object.freeze(lines),
|
||||
"frontMatterLines": Object.freeze(frontMatterLines)
|
||||
};
|
||||
|
@ -868,7 +876,7 @@ function lintInput(options, synchronous, callback) {
|
|||
const noInlineConfig = !!options.noInlineConfig;
|
||||
const resultVersion = (options.resultVersion === undefined) ?
|
||||
3 : options.resultVersion;
|
||||
const md = markdownIt({ "html": true });
|
||||
const md = markdownit({ "html": true });
|
||||
const markdownItPlugins = options.markdownItPlugins || [];
|
||||
for (const plugin of markdownItPlugins) {
|
||||
// @ts-ignore
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
/* eslint-disable n/no-unpublished-require */
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
// @ts-ignore
|
||||
const { parse, postprocess, preprocess } = require("../micromark/micromark.cjs");
|
||||
|
||||
|
@ -22,10 +21,10 @@ const { parse, postprocess, preprocess } = require("../micromark/micromark.cjs")
|
|||
*/
|
||||
|
||||
/**
|
||||
* Parses a Markdown document and returns tokens.
|
||||
* Parses a Markdown document and returns (frozen) tokens.
|
||||
*
|
||||
* @param {string} markdown Markdown document.
|
||||
* @returns {Token[]} Markdown tokens.
|
||||
* @returns {Token[]} Markdown tokens (frozen).
|
||||
*/
|
||||
function micromarkParse(markdown) {
|
||||
|
||||
|
@ -68,19 +67,15 @@ function micromarkParse(markdown) {
|
|||
};
|
||||
previous.tokens.push(current);
|
||||
} else if (kind === "exit") {
|
||||
assert.equal(type, current.type);
|
||||
assert.equal(startLine, current.startLine);
|
||||
assert.equal(startColumn, current.startColumn);
|
||||
assert.equal(endLine, current.endLine);
|
||||
assert.equal(endColumn, current.endColumn);
|
||||
assert.equal(text, current.text);
|
||||
Object.freeze(current.tokens);
|
||||
Object.freeze(current);
|
||||
// @ts-ignore
|
||||
current = history.pop();
|
||||
assert.ok(current, "Empty history");
|
||||
}
|
||||
}
|
||||
|
||||
// Return document
|
||||
Object.freeze(document);
|
||||
return document;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"build-config": "npm run build-config-schema && npm run build-config-example",
|
||||
"build-config-example": "node schema/build-config-example.js",
|
||||
"build-config-schema": "node schema/build-config-schema.js",
|
||||
"build-declaration": "tsc --allowJs --declaration --emitDeclarationOnly --module commonjs --resolveJsonModule --target es2015 lib/markdownlint.js && node scripts delete 'lib/{c,md,r}*.d.ts' 'helpers/*.d.ts'",
|
||||
"build-declaration": "tsc --allowJs --declaration --emitDeclarationOnly --module commonjs --resolveJsonModule --target es2015 lib/markdownlint.js && node scripts delete 'lib/{c,md,mi,r}*.d.{cts,ts}' 'micromark/*.d.cts' 'helpers/*.d.ts'",
|
||||
"build-demo": "node scripts copy node_modules/markdown-it/dist/markdown-it.min.js demo/markdown-it.min.js && cd demo && webpack --no-stats",
|
||||
"build-docs": "node doc-build/build-rules.mjs",
|
||||
"build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2",
|
||||
|
|
|
@ -1223,13 +1223,7 @@ test("customRulesParamsAreFrozen", (t) => {
|
|||
}
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"CHANGELOG.md",
|
||||
"CONTRIBUTING.md",
|
||||
"README.md",
|
||||
"doc/CustomRules.md",
|
||||
"doc/Rules.md"
|
||||
]
|
||||
"files": [ "README.md" ]
|
||||
};
|
||||
return markdownlint.promises.markdownlint(options).then(() => null);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue