mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD043/required-headings to add match_case parameter (fixes #613).
This commit is contained in:
parent
592a42b0cb
commit
37f74ee958
13 changed files with 125 additions and 6 deletions
|
@ -11,6 +11,7 @@ module.exports = {
|
|||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD043(params, onError) {
|
||||
const requiredHeadings = params.config.headings || params.config.headers;
|
||||
const matchCase = params.config.match_case || false;
|
||||
if (Array.isArray(requiredHeadings)) {
|
||||
const levels = {};
|
||||
for (const level of [ 1, 2, 3, 4, 5, 6 ]) {
|
||||
|
@ -21,6 +22,7 @@ module.exports = {
|
|||
let hasError = false;
|
||||
let anyHeadings = false;
|
||||
const getExpected = () => requiredHeadings[i++] || "[None]";
|
||||
const handleCase = (str) => (matchCase ? str : str.toLowerCase());
|
||||
forEachHeading(params, (heading, content) => {
|
||||
if (!hasError) {
|
||||
anyHeadings = true;
|
||||
|
@ -28,13 +30,13 @@ module.exports = {
|
|||
const expected = getExpected();
|
||||
if (expected === "*") {
|
||||
const nextExpected = getExpected();
|
||||
if (nextExpected.toLowerCase() !== actual.toLowerCase()) {
|
||||
if (handleCase(nextExpected) !== handleCase(actual)) {
|
||||
matchAny = true;
|
||||
i--;
|
||||
}
|
||||
} else if (expected === "+") {
|
||||
matchAny = true;
|
||||
} else if (expected.toLowerCase() === actual.toLowerCase()) {
|
||||
} else if (handleCase(expected) === handleCase(actual)) {
|
||||
matchAny = false;
|
||||
} else if (matchAny) {
|
||||
i--;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue