mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Add options.markdownItPlugins to support using markdown-it plugins when parsing.
This commit is contained in:
parent
ff86e1d7f1
commit
8a175955d7
5 changed files with 121 additions and 6 deletions
|
|
@ -5,7 +5,7 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { URL } = require("url");
|
||||
const md = require("markdown-it")({ "html": true });
|
||||
const markdownIt = require("markdown-it");
|
||||
const rules = require("./rules");
|
||||
const shared = require("./shared");
|
||||
|
||||
|
|
@ -289,7 +289,14 @@ function uniqueFilterForSortedErrors(value, index, array) {
|
|||
|
||||
// Lints a single string
|
||||
function lintContent(
|
||||
ruleList, name, content, config, frontMatter, noInlineConfig, resultVersion,
|
||||
ruleList,
|
||||
name,
|
||||
content,
|
||||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
noInlineConfig,
|
||||
resultVersion,
|
||||
callback) {
|
||||
// Remove UTF-8 byte order marker (if present)
|
||||
content = content.replace(/^\ufeff/, "");
|
||||
|
|
@ -410,6 +417,7 @@ function lintContent(
|
|||
function lintFile(
|
||||
ruleList,
|
||||
file,
|
||||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
noInlineConfig,
|
||||
|
|
@ -420,8 +428,8 @@ function lintFile(
|
|||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
lintContent(ruleList, file, content, config, frontMatter, noInlineConfig,
|
||||
resultVersion, callback);
|
||||
lintContent(ruleList, file, content, md, config, frontMatter,
|
||||
noInlineConfig, resultVersion, callback);
|
||||
}
|
||||
// Make a/synchronous call to read file
|
||||
if (synchronous) {
|
||||
|
|
@ -455,6 +463,12 @@ function lintInput(options, synchronous, callback) {
|
|||
const noInlineConfig = !!options.noInlineConfig;
|
||||
const resultVersion = (options.resultVersion === undefined) ?
|
||||
2 : options.resultVersion;
|
||||
const md = markdownIt({ "html": true });
|
||||
const markdownItPlugins = options.markdownItPlugins || [];
|
||||
markdownItPlugins.forEach(function forPlugin(plugin) {
|
||||
// @ts-ignore
|
||||
md.use(...plugin);
|
||||
});
|
||||
const results = newResults(ruleList);
|
||||
// Helper to lint the next string or file
|
||||
function lintNextItem() {
|
||||
|
|
@ -476,6 +490,7 @@ function lintInput(options, synchronous, callback) {
|
|||
ruleList,
|
||||
item,
|
||||
strings[item] || "",
|
||||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
noInlineConfig,
|
||||
|
|
@ -486,6 +501,7 @@ function lintInput(options, synchronous, callback) {
|
|||
lintFile(
|
||||
ruleList,
|
||||
item,
|
||||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
noInlineConfig,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue