mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
parent
fd06a50ee5
commit
e9b3cc4c18
17 changed files with 232 additions and 25 deletions
38
lib/md048.js
Normal file
38
lib/md048.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { addErrorDetailIf } = require("../helpers");
|
||||
|
||||
function fencedCodeBlockStyleFor(markup) {
|
||||
switch (markup[0]) {
|
||||
case "~":
|
||||
return "tilde";
|
||||
default:
|
||||
return "backtick";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD048", "code-fence-style" ],
|
||||
"description": "Code fence style",
|
||||
"tags": [ "code" ],
|
||||
"function": function MD048(params, onError) {
|
||||
const style = params.config.style || "consistent";
|
||||
let expectedStyle = style;
|
||||
params.tokens
|
||||
.filter((token) => token.type === "fence")
|
||||
.forEach((fenceToken) => {
|
||||
const { lineNumber, markup } = fenceToken;
|
||||
if (expectedStyle === "consistent") {
|
||||
expectedStyle = fencedCodeBlockStyleFor(markup);
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
lineNumber,
|
||||
expectedStyle,
|
||||
fencedCodeBlockStyleFor(markup)
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue