mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-23 09:20:12 +01:00
Allow options.markdownItFactory to be implemented asynchronously so the markdown-it parser import can be deferred.
This commit is contained in:
parent
d4b981bcb3
commit
44c302fe0b
6 changed files with 448 additions and 249 deletions
|
|
@ -5,7 +5,7 @@
|
|||
const { newLineRe } = require("../helpers");
|
||||
|
||||
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/52529
|
||||
/** @typedef {import("markdownlint").MarkdownItFactory} MarkdownItFactory */
|
||||
/** @typedef {import("markdownlint").MarkdownIt} MarkdownIt */
|
||||
// @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
|
||||
|
|
@ -154,13 +154,12 @@ function annotateAndFreezeTokens(tokens, lines) {
|
|||
/**
|
||||
* Gets an array of markdown-it tokens for the input.
|
||||
*
|
||||
* @param {MarkdownItFactory} markdownItFactory Function to create a markdown-it parser.
|
||||
* @param {MarkdownIt} markdownIt Instance of the markdown-it parser.
|
||||
* @param {string} content Markdown content.
|
||||
* @param {string[]} lines Lines of Markdown content.
|
||||
* @returns {MarkdownItToken[]} Array of markdown-it tokens.
|
||||
*/
|
||||
function getMarkdownItTokens(markdownItFactory, content, lines) {
|
||||
const markdownIt = markdownItFactory();
|
||||
function getMarkdownItTokens(markdownIt, content, lines) {
|
||||
const tokens = markdownIt.parse(content, {});
|
||||
annotateAndFreezeTokens(tokens, lines);
|
||||
return tokens;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue