diff --git a/.github/workflows/validate-markdown.yaml b/.github/workflows/validate-markdown.yaml index b655726..9fc5335 100644 --- a/.github/workflows/validate-markdown.yaml +++ b/.github/workflows/validate-markdown.yaml @@ -26,6 +26,6 @@ jobs: with: node-version: '20.x' - name: Validate markdown - run: npx --yes mdv versions/*.md + run: "npm run markdown:validate" - name: Lint markdown - run: npx --yes markdownlint-cli --config .markdownlint.yaml versions/*.md + run: "npm run markdown:lint" diff --git a/package.json b/package.json index f7d9471..8fba22a 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,13 @@ ], "scripts": { "build": "bash ./scripts/md2html/build.sh", - "format-markdown": "bash ./scripts/format-markdown.sh ./versions/*.md", + "markdown:format:versions": "bash ./scripts/format-markdown.sh --config ./versions/.markdownlint.yaml ./versions/*.md", + "markdown:format:schemas": "bash ./scripts/format-markdown.sh --config ./schemas/.markdownlint.yaml ./schemas/**/*.md", + "markdown:format": "npm run markdown:format:schemas && npm run markdown:format:versions", + "markdown:lint:schemas": "npx --yes markdownlint-cli --config ./schemas/.markdownlint.yaml ./schemas/**/*.md", + "markdown:lint:versions": "npx --yes markdownlint-cli --config ./versions/.markdownlint.yaml ./versions/*.md", + "markdown:lint": "npm run markdown:lint:schemas && npm run markdown:lint:versions", + "markdown:validate": "npx --yes mdv ./{versions,schemas/**}/*.md", "test": "c8 --100 vitest --watch=false && bash scripts/schema-test-coverage.sh" } } diff --git a/schemas/.markdownlint.yaml b/schemas/.markdownlint.yaml new file mode 100644 index 0000000..eccd08c --- /dev/null +++ b/schemas/.markdownlint.yaml @@ -0,0 +1,14 @@ +# Unordered list indentation +MD007: + indent: 2 + +MD012: false # allow blank lines + +MD013: + line_length: 800 + tables: false + +MD024: false # duplicate headings +MD032: false # blanks-around-lists Lists should be surrounded by blank lines +MD033: false # inline HTML +MD047: false # single-trailing-newline Files should end with a single newline character diff --git a/scripts/format-markdown.sh b/scripts/format-markdown.sh index c04b971..274195e 100755 --- a/scripts/format-markdown.sh +++ b/scripts/format-markdown.sh @@ -2,7 +2,28 @@ SRCDIR="$(dirname "${BASH_SOURCE[0]}")" # check on Windows -for filename in $*; do +CONFIG="" + +while [[ $# -gt 0 ]]; do + case $1 in + --config) + CONFIG="$2" + shift # Remove --config from processing + shift # Remove the value from processing + ;; + *) + FILES+="$1 " + shift # Move to the next argument + ;; + esac +done + +if [ -z "$CONFIG" ]; then + echo "Error: --config parameter is required." + exit 1 +fi + +for filename in $FILES; do # mostly to format code blocks with examples, unfortunately messes up bullet lists and tables npx prettier --write --single-quote $filename @@ -11,5 +32,5 @@ for filename in $*; do sed -E -e "s/ +\|/ |/g" -e "s/\| +/| /g" -e "s/-----+/----/g" $filename > $filename.tmp && mv $filename.tmp $filename # repair the bullet lists and various other markdown formatting issues - npx --yes markdownlint-cli --fix --config $SRCDIR/../.markdownlint.yaml $filename + npx --yes markdownlint-cli --fix --config "$CONFIG" $filename done diff --git a/.markdownlint.yaml b/versions/.markdownlint.yaml similarity index 100% rename from .markdownlint.yaml rename to versions/.markdownlint.yaml