mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01: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
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue