From d4032df767b84e5f7b7ae24f99ee176aa47763ef Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 3 Nov 2023 03:42:05 -0700 Subject: [PATCH] Add tmp/format-headers.sh script from Landon With a slight modification so that the script uses git ls-files so that it only acts on files called README.md under the directories of the years (i.e. '[0-9]{4}/*README.md') that are under git control this script formats headers so that the spacing before lines starting with '##' (as in '^##') are correct. It checks for specific header names. More could be added if necessary and if any heading level is wrong or it is decided that a different heading level might be better the regexp can be modified to fix it as well. This script will be useful to run after every README.md file has been updated. Added to tmp/ as it is likely (or possibly?) a temporary tool that might not be needed after the temp-test-ioccc repo is merged back into the winner repo. On the other hand it might be useful to use after new contests are run or even after some major edits of README.md files. Uses perl in a bash loop. --- tmp/format-headers.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 tmp/format-headers.sh diff --git a/tmp/format-headers.sh b/tmp/format-headers.sh new file mode 100755 index 000000000..dedf805d4 --- /dev/null +++ b/tmp/format-headers.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# +# format-headers.sh - script that formats headers in README.md files so that +# before a line that starts with '##' (as in '^##') that have specific names +# there are two blank lines (\n\n). +# +# Script written by Landon with minor improvements by Cody Boone Ferguson where +# now it only acts on files under git control rather than any README.md file in +# the [0-9]{4} directories. +# + +for i in "$(git ls-files '[0-9][0-9][0-9][0-9]/*README.md')"; do + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(To build):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Bugs and \(Mis\)features):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(To use):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Try):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Original code):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Original build):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Original try):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Original use):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Alternate code):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Alternate build):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Alternate try):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Alternate use):?\n\n*([^\n])?/$1\n\n### $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Judges. remarks):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Author.s remarks):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Authors. remarks):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" + perl -0777 -p -i -e 's/([^\n]\n)\n*##*[[:space:]]*(Copyright and CC BY-SA 4.0 License):?\n\n*([^\n])?/$1\n\n## $2:\n\n$3/' "$i" +done