mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Expose shared.js helper code for custom rule authors (fixes #134).
This commit is contained in:
parent
f614f3e1ce
commit
7e980401b8
52 changed files with 283 additions and 184 deletions
11
lib/md038.js
11
lib/md038.js
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const shared = require("./shared");
|
||||
const { addErrorContext, filterTokens, forEachInlineCodeSpan, newLineRe } =
|
||||
require("../helpers");
|
||||
|
||||
const startRe = /^\s([^`]|$)/;
|
||||
const endRe = /[^`]\s$/;
|
||||
|
|
@ -12,16 +13,16 @@ module.exports = {
|
|||
"description": "Spaces inside code span elements",
|
||||
"tags": [ "whitespace", "code" ],
|
||||
"function": function MD038(params, onError) {
|
||||
shared.filterTokens(params, "inline", (token) => {
|
||||
filterTokens(params, "inline", (token) => {
|
||||
if (token.children.some((child) => child.type === "code_inline")) {
|
||||
const tokenLines = params.lines.slice(token.map[0], token.map[1]);
|
||||
shared.forEachInlineCodeSpan(
|
||||
forEachInlineCodeSpan(
|
||||
tokenLines.join("\n"),
|
||||
(code, lineIndex, columnIndex, tickCount) => {
|
||||
let rangeIndex = columnIndex - tickCount;
|
||||
let rangeLength = code.length + (2 * tickCount);
|
||||
let rangeLineOffset = 0;
|
||||
const codeLines = code.split(shared.newLineRe);
|
||||
const codeLines = code.split(newLineRe);
|
||||
const left = startRe.test(code);
|
||||
const right = !left && endRe.test(code);
|
||||
if (right && (codeLines.length > 1)) {
|
||||
|
|
@ -34,7 +35,7 @@ module.exports = {
|
|||
}
|
||||
const context = tokenLines[lineIndex + rangeLineOffset]
|
||||
.substring(rangeIndex, rangeIndex + rangeLength);
|
||||
shared.addErrorContext(
|
||||
addErrorContext(
|
||||
onError, token.lineNumber + lineIndex + rangeLineOffset,
|
||||
context, left, right, [ rangeIndex + 1, rangeLength ]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue