mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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/md021.js
11
lib/md021.js
|
@ -2,7 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const shared = require("./shared");
|
||||
const { addErrorContext, filterTokens, headingStyleFor, rangeFromRegExp } =
|
||||
require("../helpers");
|
||||
|
||||
const atxClosedHeadingSpaceRe = /(?:^#+\s\s+?\S)|(?:\S\s\s+?#+\s*$)/;
|
||||
|
||||
|
@ -11,14 +12,14 @@ module.exports = {
|
|||
"description": "Multiple spaces inside hashes on closed atx style heading",
|
||||
"tags": [ "headings", "headers", "atx_closed", "spaces" ],
|
||||
"function": function MD021(params, onError) {
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (shared.headingStyleFor(token) === "atx_closed") {
|
||||
filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (headingStyleFor(token) === "atx_closed") {
|
||||
const left = /^#+\s\s/.test(token.line);
|
||||
const right = /\s\s#+$/.test(token.line);
|
||||
if (left || right) {
|
||||
shared.addErrorContext(onError, token.lineNumber, token.line.trim(),
|
||||
addErrorContext(onError, token.lineNumber, token.line.trim(),
|
||||
left, right,
|
||||
shared.rangeFromRegExp(token.line, atxClosedHeadingSpaceRe));
|
||||
rangeFromRegExp(token.line, atxClosedHeadingSpaceRe));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue