Update MD043/required-headings to add match_case parameter (fixes #613).

This commit is contained in:
Mateus Ferreira 2022-10-22 03:15:50 -04:00 committed by GitHub
parent 592a42b0cb
commit 37f74ee958
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 125 additions and 6 deletions

View file

@ -4297,6 +4297,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]) {
@ -4307,6 +4308,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;
@ -4314,7 +4316,7 @@ module.exports = {
const expected = getExpected();
if (expected === "*") {
const nextExpected = getExpected();
if (nextExpected.toLowerCase() !== actual.toLowerCase()) {
if (handleCase(nextExpected) !== handleCase(actual)) {
matchAny = true;
i--;
}
@ -4322,7 +4324,7 @@ module.exports = {
else if (expected === "+") {
matchAny = true;
}
else if (expected.toLowerCase() === actual.toLowerCase()) {
else if (handleCase(expected) === handleCase(actual)) {
matchAny = false;
}
else if (matchAny) {