Skip to content

Commit

Permalink
bash script for markdown formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl committed Aug 27, 2024
1 parent 5382de7 commit 4a8c4ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
13 changes: 13 additions & 0 deletions scripts/format-markdown.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4a8c4ca

Please sign in to comment.