From 4a8c4cac2131cc51d11bd74e96983df8a9368902 Mon Sep 17 00:00:00 2001 From: Ralf Handl Date: Tue, 27 Aug 2024 10:24:18 +0200 Subject: [PATCH] bash script for markdown formatting --- package.json | 2 +- scripts/format-markdown.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 scripts/format-markdown.sh diff --git a/package.json b/package.json index 34b87570b3..5ae2cba9bc 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,6 @@ "API" ], "scripts": { - "format-markdown": "npx prettier --write --single-quote versions/3.0.4.md && sed -i '' -E -e 's/ +\\|/ |/g' -e 's/\\| +/| /g' -e 's/-----+/----/g' versions/3.0.4.md && npx --yes markdownlint-cli --fix --config .markdownlint.yaml versions/3.0.4.md" + "format-markdown": "bash ./scripts/format-markdown.sh ./versions/3.0.4.md" } } diff --git a/scripts/format-markdown.sh b/scripts/format-markdown.sh new file mode 100644 index 0000000000..b592a6b073 --- /dev/null +++ b/scripts/format-markdown.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +for filename in $*; do + # mostly to format code blocks with examples, unfortunately messes up bullet lists and tables + npx prettier --write --single-quote $filename + + # repair the tables: remove superfluos spaces and dashes that make diffing revisions harder + # and sed -i is not portable, so we need to use a temporary file + 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 .markdownlint.yaml $filename +done