mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-21 08:20:12 +01:00
Update MD026/no-trailing-punctuation to handle empty punctuation paramater, escape for RegExp (fixes #205).
This commit is contained in:
parent
d336a11665
commit
91b4fcd55f
6 changed files with 39 additions and 13 deletions
14
lib/md026.js
14
lib/md026.js
|
|
@ -2,17 +2,21 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, allPunctuation, forEachHeading, rangeFromRegExp } =
|
||||
require("../helpers");
|
||||
const { addError, allPunctuation, escapeForRegExp, forEachHeading,
|
||||
rangeFromRegExp } = require("../helpers");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD026", "no-trailing-punctuation" ],
|
||||
"description": "Trailing punctuation in heading",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD026(params, onError) {
|
||||
const punctuation = params.config.punctuation || allPunctuation;
|
||||
const trailingPunctuationRe = new RegExp("[" + punctuation + "]$");
|
||||
forEachHeading(params, function forHeading(heading, content) {
|
||||
let punctuation = params.config.punctuation;
|
||||
if (punctuation === undefined) {
|
||||
punctuation = allPunctuation;
|
||||
}
|
||||
const trailingPunctuationRe =
|
||||
new RegExp("[" + escapeForRegExp(punctuation) + "]$");
|
||||
forEachHeading(params, (heading, content) => {
|
||||
const match = trailingPunctuationRe.exec(content);
|
||||
if (match) {
|
||||
addError(onError, heading.lineNumber,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue