mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Introduce options.markdownItFactory (and remove options.markdownItPlugins) so the markdown-it parser can be removed as a direct dependency because it is no longer used by default.
This commit is contained in:
parent
3cbe1cb6c5
commit
d4b981bcb3
11 changed files with 172 additions and 67 deletions
|
|
@ -447,7 +447,7 @@ function getEnabledRulesPerLineNumber(
|
|||
* names.
|
||||
* @param {string} name Identifier for the content.
|
||||
* @param {string} content Markdown content.
|
||||
* @param {Plugin[]} markdownItPlugins Additional plugins.
|
||||
* @param {MarkdownItFactory} markdownItFactory Function to create a markdown-it parser.
|
||||
* @param {Configuration} config Configuration object.
|
||||
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||
* @param {RegExp | null} frontMatter Regular expression for front matter.
|
||||
|
|
@ -462,7 +462,7 @@ function lintContent(
|
|||
aliasToRuleNames,
|
||||
name,
|
||||
content,
|
||||
markdownItPlugins,
|
||||
markdownItFactory,
|
||||
config,
|
||||
configParsers,
|
||||
frontMatter,
|
||||
|
|
@ -502,7 +502,7 @@ function lintContent(
|
|||
// Parse content into lines and get markdown-it tokens
|
||||
const lines = content.split(helpers.newLineRe);
|
||||
const markdownitTokens = needMarkdownItTokens ?
|
||||
requireMarkdownItCjs().getMarkdownItTokens(markdownItPlugins, preClearedContent, lines) :
|
||||
requireMarkdownItCjs().getMarkdownItTokens(markdownItFactory, preClearedContent, lines) :
|
||||
[];
|
||||
// Create (frozen) parameters for rules
|
||||
/** @type {MarkdownParsers} */
|
||||
|
|
@ -754,10 +754,9 @@ function lintContent(
|
|||
* Lints a file containing Markdown content.
|
||||
*
|
||||
* @param {Rule[]} ruleList List of rules.
|
||||
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule
|
||||
* names.
|
||||
* @param {Object.<string, string[]>} aliasToRuleNames Map of alias to rule names.
|
||||
* @param {string} file Path of file to lint.
|
||||
* @param {Plugin[]} markdownItPlugins Additional plugins.
|
||||
* @param {MarkdownItFactory} markdownItFactory Function to create a markdown-it parser.
|
||||
* @param {Configuration} config Configuration object.
|
||||
* @param {ConfigurationParser[] | null} configParsers Configuration parsers.
|
||||
* @param {RegExp | null} frontMatter Regular expression for front matter.
|
||||
|
|
@ -773,7 +772,7 @@ function lintFile(
|
|||
ruleList,
|
||||
aliasToRuleNames,
|
||||
file,
|
||||
markdownItPlugins,
|
||||
markdownItFactory,
|
||||
config,
|
||||
configParsers,
|
||||
frontMatter,
|
||||
|
|
@ -793,7 +792,7 @@ function lintFile(
|
|||
aliasToRuleNames,
|
||||
file,
|
||||
content,
|
||||
markdownItPlugins,
|
||||
markdownItFactory,
|
||||
config,
|
||||
configParsers,
|
||||
frontMatter,
|
||||
|
|
@ -860,7 +859,9 @@ function lintInput(options, synchronous, callback) {
|
|||
const resultVersion = (options.resultVersion === undefined) ?
|
||||
3 :
|
||||
options.resultVersion;
|
||||
const markdownItPlugins = options.markdownItPlugins || [];
|
||||
const markdownItFactory =
|
||||
options.markdownItFactory ||
|
||||
(() => { throw new Error("The option 'markdownItFactory' was required (due to the option 'customRules' including a rule requiring the 'markdown-it' parser), but 'markdownItFactory' was not set."); });
|
||||
const fs = options.fs || nodeFs;
|
||||
const aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
||||
const results = newResults(ruleList);
|
||||
|
|
@ -892,7 +893,7 @@ function lintInput(options, synchronous, callback) {
|
|||
ruleList,
|
||||
aliasToRuleNames,
|
||||
currentItem,
|
||||
markdownItPlugins,
|
||||
markdownItFactory,
|
||||
config,
|
||||
configParsers,
|
||||
frontMatter,
|
||||
|
|
@ -911,7 +912,7 @@ function lintInput(options, synchronous, callback) {
|
|||
aliasToRuleNames,
|
||||
currentItem,
|
||||
strings[currentItem] || "",
|
||||
markdownItPlugins,
|
||||
markdownItFactory,
|
||||
config,
|
||||
configParsers,
|
||||
frontMatter,
|
||||
|
|
@ -1473,6 +1474,29 @@ export function getVersion() {
|
|||
* @property {RuleFunction} function Rule implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Method used by the markdown-it parser to parse input.
|
||||
*
|
||||
* @callback MarkdownItParse
|
||||
* @param {string} src Source string.
|
||||
* @param {Object} env Environment sandbox.
|
||||
* @returns {import("markdown-it").Token[]} Tokens.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Instance of the markdown-it parser.
|
||||
*
|
||||
* @typedef MarkdownIt
|
||||
* @property {MarkdownItParse} parse Method to parse input.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets an instance of the markdown-it parser. Any plugins should already have been loaded.
|
||||
*
|
||||
* @callback MarkdownItFactory
|
||||
* @returns {MarkdownIt} Instance of the markdown-it parser.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
|
|
@ -1484,7 +1508,7 @@ export function getVersion() {
|
|||
* @property {RegExp | null} [frontMatter] Front matter pattern.
|
||||
* @property {Object} [fs] File system implementation.
|
||||
* @property {boolean} [handleRuleFailures] True to catch exceptions.
|
||||
* @property {Plugin[]} [markdownItPlugins] Additional plugins.
|
||||
* @property {MarkdownItFactory} [markdownItFactory] Function to create a markdown-it parser.
|
||||
* @property {boolean} [noInlineConfig] True to ignore HTML directives.
|
||||
* @property {number} [resultVersion] Results object version.
|
||||
* @property {Object.<string, string>} [strings] Strings to lint.
|
||||
|
|
@ -1501,7 +1525,7 @@ export function getVersion() {
|
|||
*
|
||||
* @callback ToStringCallback
|
||||
* @param {boolean} [ruleAliases] True to use rule aliases.
|
||||
* @returns {string}
|
||||
* @returns {string} Pretty-printed results.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue