mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Improve highlighting for MD038/no-space-in-code, add more tests.
This commit is contained in:
parent
681e8bae4e
commit
5fee0a921d
4 changed files with 87 additions and 20 deletions
|
|
@ -220,11 +220,12 @@ function lintContent(
|
|||
// Configure rule
|
||||
params.options = mergedRules[rule.name];
|
||||
var errors = [];
|
||||
function addError(lineNumber, detail, context) {
|
||||
function addError(lineNumber, detail, context, range) {
|
||||
errors.push({
|
||||
"lineNumber": lineNumber + frontMatterLines.length,
|
||||
"detail": detail || null,
|
||||
"context": context || null
|
||||
"context": context || null,
|
||||
"range": range || null
|
||||
});
|
||||
}
|
||||
errors.add = function add(lineNumber) {
|
||||
|
|
@ -238,18 +239,19 @@ function lintContent(
|
|||
addError(lineNumber, "Expected: " + expected + "; Actual: " + actual);
|
||||
}
|
||||
};
|
||||
errors.addContext = function addContext(lineNumber, context, left, right) {
|
||||
if (context.length <= 30) {
|
||||
// Nothing to do
|
||||
} else if (left && right) {
|
||||
context = context.substr(0, 15) + "..." + context.substr(-15);
|
||||
} else if (right) {
|
||||
context = "..." + context.substr(-30);
|
||||
} else {
|
||||
context = context.substr(0, 30) + "...";
|
||||
}
|
||||
addError(lineNumber, null, context);
|
||||
};
|
||||
errors.addContext =
|
||||
function addContext(lineNumber, context, left, right, range) {
|
||||
if (context.length <= 30) {
|
||||
// Nothing to do
|
||||
} else if (left && right) {
|
||||
context = context.substr(0, 15) + "..." + context.substr(-15);
|
||||
} else if (right) {
|
||||
context = "..." + context.substr(-30);
|
||||
} else {
|
||||
context = context.substr(0, 30) + "...";
|
||||
}
|
||||
addError(lineNumber, null, context, range);
|
||||
};
|
||||
rule.func(params, errors);
|
||||
// Record any errors (significant performance benefit from length check)
|
||||
if (errors.length) {
|
||||
|
|
@ -263,9 +265,9 @@ function lintContent(
|
|||
if (resultVersion === 0) {
|
||||
return error.lineNumber;
|
||||
}
|
||||
var range = null;
|
||||
var range = error.range;
|
||||
var regexp = rule.regexp;
|
||||
if (regexp) {
|
||||
if (!range && regexp) {
|
||||
if (typeof regexp === "function") {
|
||||
regexp = regexp(params.options);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue