mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Use proper YAML serialization to produce correct example output for multi-item arrays (fixes #721).
This commit is contained in:
parent
7c818914fb
commit
3e454481fd
4 changed files with 28 additions and 22 deletions
|
|
@ -89,7 +89,8 @@
|
||||||
"tv4": "1.3.0",
|
"tv4": "1.3.0",
|
||||||
"typescript": "4.9.5",
|
"typescript": "4.9.5",
|
||||||
"webpack": "5.75.0",
|
"webpack": "5.75.0",
|
||||||
"webpack-cli": "5.0.1"
|
"webpack-cli": "5.0.1",
|
||||||
|
"yaml": "2.2.1"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"markdown",
|
"markdown",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
// Example markdownlint configuration with all properties set to their default value
|
||||||
{
|
{
|
||||||
// Example markdownlint JSON(C) configuration with all properties set to their default value
|
|
||||||
|
|
||||||
// Default state for all rules
|
// Default state for all rules
|
||||||
"default": true,
|
"default": true,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Example markdownlint YAML configuration with all properties set to their default value
|
# Example markdownlint configuration with all properties set to their default value
|
||||||
|
|
||||||
# Default state for all rules
|
# Default state for all rules
|
||||||
default: true
|
default: true
|
||||||
|
|
@ -257,6 +257,5 @@ MD052: true
|
||||||
# MD053/link-image-reference-definitions - Link and image reference definitions should be needed
|
# MD053/link-image-reference-definitions - Link and image reference definitions should be needed
|
||||||
MD053:
|
MD053:
|
||||||
# Ignored definitions
|
# Ignored definitions
|
||||||
ignored_definitions: [
|
ignored_definitions:
|
||||||
"//"
|
- "//"
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
const fs = require("node:fs");
|
const fs = require("node:fs");
|
||||||
const path = require("node:path");
|
const path = require("node:path");
|
||||||
|
const yaml = require("yaml");
|
||||||
const configSchema = require("./markdownlint-config-schema.json");
|
const configSchema = require("./markdownlint-config-schema.json");
|
||||||
|
|
||||||
const configExample = {};
|
const configExample = {};
|
||||||
|
|
@ -25,29 +26,34 @@ for (const rule in configSchema.properties) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const configStringJson = JSON.stringify(configExample, null, 2)
|
const transformComments = (input, commentPrefix) => (
|
||||||
|
commentPrefix +
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
.replace(/^\{/, "{\n // Example markdownlint JSON(C) configuration with all properties set to their default value")
|
" Example markdownlint configuration with all properties set to their default value\n" +
|
||||||
.replace(/(\s+)"[^-"]+-description": "(.+)",/g, "\n$1// $2")
|
input
|
||||||
.replace(/"[^-"]+-sub-description": "(.+)",/g, "// $1");
|
// eslint-disable-next-line max-len
|
||||||
|
.replace(/^(\s*)[^-\s]+-sub-description"?: "?([^"\n]+)"?,?$/gm, "$1" + commentPrefix + " $2")
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
.replace(/^(\s*)[^-\s]+-description"?: "?([^"\n]+)"?,?$/gm, "\n$1" + commentPrefix + " $2")
|
||||||
|
);
|
||||||
|
|
||||||
|
const configStringJson = JSON.stringify(configExample, null, 2);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(__dirname, ".markdownlint.jsonc"),
|
path.join(__dirname, ".markdownlint.jsonc"),
|
||||||
configStringJson,
|
transformComments(configStringJson, "//"),
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
|
|
||||||
const configStringYaml = configStringJson
|
const configStringYaml = yaml.stringify(
|
||||||
.replace(/JSON\(C\)/, "YAML")
|
configExample,
|
||||||
.replace(/\n {2}/g, "\n")
|
{
|
||||||
.replace(/\/\/ /g, "# ")
|
"lineWidth": 0,
|
||||||
.replace(/(\s*)"([^"]+)":/g, "$1$2:")
|
"defaultStringType": "QUOTE_DOUBLE",
|
||||||
.replace(/: \{/g, ":")
|
"defaultKeyType": "PLAIN"
|
||||||
.replace(/\n\}/g, "")
|
}
|
||||||
.replace(/,\n/g, "\n")
|
);
|
||||||
.replace(/^\{\n/, "")
|
|
||||||
.replace(/\}$/, "");
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(__dirname, ".markdownlint.yaml"),
|
path.join(__dirname, ".markdownlint.yaml"),
|
||||||
configStringYaml,
|
transformComments(configStringYaml, "#"),
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue