mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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",
|
||||
"typescript": "4.9.5",
|
||||
"webpack": "5.75.0",
|
||||
"webpack-cli": "5.0.1"
|
||||
"webpack-cli": "5.0.1",
|
||||
"yaml": "2.2.1"
|
||||
},
|
||||
"keywords": [
|
||||
"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": 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: true
|
||||
|
@ -257,6 +257,5 @@ MD052: true
|
|||
# MD053/link-image-reference-definitions - Link and image reference definitions should be needed
|
||||
MD053:
|
||||
# Ignored definitions
|
||||
ignored_definitions: [
|
||||
"//"
|
||||
]
|
||||
ignored_definitions:
|
||||
- "//"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const yaml = require("yaml");
|
||||
const configSchema = require("./markdownlint-config-schema.json");
|
||||
|
||||
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
|
||||
.replace(/^\{/, "{\n // Example markdownlint JSON(C) configuration with all properties set to their default value")
|
||||
.replace(/(\s+)"[^-"]+-description": "(.+)",/g, "\n$1// $2")
|
||||
.replace(/"[^-"]+-sub-description": "(.+)",/g, "// $1");
|
||||
" Example markdownlint configuration with all properties set to their default value\n" +
|
||||
input
|
||||
// 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(
|
||||
path.join(__dirname, ".markdownlint.jsonc"),
|
||||
configStringJson,
|
||||
transformComments(configStringJson, "//"),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
const configStringYaml = configStringJson
|
||||
.replace(/JSON\(C\)/, "YAML")
|
||||
.replace(/\n {2}/g, "\n")
|
||||
.replace(/\/\/ /g, "# ")
|
||||
.replace(/(\s*)"([^"]+)":/g, "$1$2:")
|
||||
.replace(/: \{/g, ":")
|
||||
.replace(/\n\}/g, "")
|
||||
.replace(/,\n/g, "\n")
|
||||
.replace(/^\{\n/, "")
|
||||
.replace(/\}$/, "");
|
||||
const configStringYaml = yaml.stringify(
|
||||
configExample,
|
||||
{
|
||||
"lineWidth": 0,
|
||||
"defaultStringType": "QUOTE_DOUBLE",
|
||||
"defaultKeyType": "PLAIN"
|
||||
}
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, ".markdownlint.yaml"),
|
||||
configStringYaml,
|
||||
transformComments(configStringYaml, "#"),
|
||||
"utf8"
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue