mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-22 08:50: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
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
const { newLineRe } = require("../helpers");
|
||||
|
||||
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
||||
/** @typedef {import("markdownlint").MarkdownItFactory} MarkdownItFactory */
|
||||
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
||||
/** @typedef {import("markdownlint").MarkdownItToken} MarkdownItToken */
|
||||
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
||||
|
|
@ -97,7 +99,7 @@ function freezeToken(token) {
|
|||
/**
|
||||
* Annotate tokens with line/lineNumber and freeze them.
|
||||
*
|
||||
* @param {Object[]} tokens Array of markdown-it tokens.
|
||||
* @param {import("markdown-it").Token[]} tokens Array of markdown-it tokens.
|
||||
* @param {string[]} lines Lines of Markdown content.
|
||||
* @returns {void}
|
||||
*/
|
||||
|
|
@ -152,21 +154,15 @@ function annotateAndFreezeTokens(tokens, lines) {
|
|||
/**
|
||||
* Gets an array of markdown-it tokens for the input.
|
||||
*
|
||||
* @param {Plugin[]} markdownItPlugins Additional plugins.
|
||||
* @param {MarkdownItFactory} markdownItFactory Function to create a markdown-it parser.
|
||||
* @param {string} content Markdown content.
|
||||
* @param {string[]} lines Lines of Markdown content.
|
||||
* @returns {MarkdownItToken} Array of markdown-it tokens.
|
||||
* @returns {MarkdownItToken[]} Array of markdown-it tokens.
|
||||
*/
|
||||
function getMarkdownItTokens(markdownItPlugins, content, lines) {
|
||||
const markdownit = require("markdown-it");
|
||||
const md = markdownit({ "html": true });
|
||||
for (const plugin of markdownItPlugins) {
|
||||
// @ts-ignore
|
||||
md.use(...plugin);
|
||||
}
|
||||
const tokens = md.parse(content, {});
|
||||
function getMarkdownItTokens(markdownItFactory, content, lines) {
|
||||
const markdownIt = markdownItFactory();
|
||||
const tokens = markdownIt.parse(content, {});
|
||||
annotateAndFreezeTokens(tokens, lines);
|
||||
// @ts-ignore
|
||||
return tokens;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue