mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Remove params.tokenLists to simplify custom rule API.
This commit is contained in:
parent
7a752784f1
commit
b33acb81d9
2 changed files with 100 additions and 94 deletions
|
@ -141,7 +141,6 @@ function removeFrontMatter(content, frontMatter) {
|
|||
// Annotate tokens with line/lineNumber
|
||||
function annotateTokens(tokens, lines) {
|
||||
var tbodyMap = null;
|
||||
var tokenLists = {};
|
||||
tokens.forEach(function forToken(token) {
|
||||
// Handle missing maps for table body
|
||||
if (token.type === "tbody_open") {
|
||||
|
@ -172,12 +171,7 @@ function annotateTokens(tokens, lines) {
|
|||
}
|
||||
});
|
||||
}
|
||||
if (!tokenLists[token.type]) {
|
||||
tokenLists[token.type] = [];
|
||||
}
|
||||
tokenLists[token.type].push(token);
|
||||
});
|
||||
return tokenLists;
|
||||
}
|
||||
|
||||
// Map rule names/tags to canonical rule name
|
||||
|
@ -292,19 +286,16 @@ function lintContent(
|
|||
ruleList, content, config, frontMatter, noInlineConfig, resultVersion,
|
||||
callback) {
|
||||
// Remove UTF-8 byte order marker (if present)
|
||||
if (content.charCodeAt(0) === 0xfeff) {
|
||||
content = content.slice(1);
|
||||
}
|
||||
content = content.replace(/^\ufeff/, "");
|
||||
// Remove front matter
|
||||
var removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
||||
content = removeFrontMatterResult.content;
|
||||
var frontMatterLines = removeFrontMatterResult.frontMatterLines;
|
||||
// Ignore the content of HTML comments
|
||||
content = shared.clearHtmlCommentText(content);
|
||||
content = shared.clearHtmlCommentText(removeFrontMatterResult.content);
|
||||
// Parse content into tokens and lines
|
||||
var tokens = md.parse(content, {});
|
||||
var lines = content.split(shared.newLineRe);
|
||||
var tokenLists = annotateTokens(tokens, lines);
|
||||
annotateTokens(tokens, lines);
|
||||
var aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
||||
var effectiveConfig = getEffectiveConfig(ruleList, config, aliasToRuleNames);
|
||||
var enabledRulesPerLineNumber = getEnabledRulesPerLineNumber(
|
||||
|
@ -313,10 +304,10 @@ function lintContent(
|
|||
// Create parameters for rules
|
||||
var params = {
|
||||
"tokens": tokens,
|
||||
"tokenLists": tokenLists,
|
||||
"lines": lines,
|
||||
"frontMatterLines": frontMatterLines
|
||||
};
|
||||
shared.makeTokenCache(params);
|
||||
// Function to run for each rule
|
||||
var result = (resultVersion === 0) ? {} : [];
|
||||
function forRule(rule) {
|
||||
|
@ -402,8 +393,10 @@ function lintContent(
|
|||
try {
|
||||
ruleList.forEach(forRule);
|
||||
} catch (ex) {
|
||||
shared.makeTokenCache(null);
|
||||
return callback(ex);
|
||||
}
|
||||
shared.makeTokenCache(null);
|
||||
callback(null, result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue