fix(convert-formula.sh): fix reST underlining during conversion

Assuming the Python convention for section headings of:

  = for sections
  - for subsections
  ^ for subsubsections
  " for paragraphs

as described at https://devguide.python.org/documenting/#sections
This commit is contained in:
Dafydd Jones 2021-08-13 21:25:00 +01:00
parent 84cb63fc8e
commit 11068afae9

View file

@ -25,6 +25,10 @@ sedi() {
fi
}
repeat_char() {
printf %"${NEW_NAME_LENGTH}"s | tr " " "$1"
}
args() {
if [ $# -ne 1 ]; then
usage
@ -32,6 +36,7 @@ args() {
fi
NEW_NAME=$1
NEW_NAME_PYSAFE=$(echo "$NEW_NAME" | sed 's/-/__/g')
NEW_NAME_LENGTH=${#NEW_NAME}
if echo "$NEW_NAME" | grep -E --quiet --invert-match '^[a-z0-9_-]+$'; then
usage
exit 1
@ -78,6 +83,16 @@ convert_formula() {
sedi "/^\( \)TEMPLATE\(:\)$/s//\1${NEW_NAME_PYSAFE}\2/" "$filename"
done
# Where a section heading contains TEMPLATE, ensure the length of underlining
# on the following line matches the length of the new formula name
sedi "/TEMPLATE/{
n
s/========/$(repeat_char =)/
s/--------/$(repeat_char -)/
s/\^^^^^^^^/$(repeat_char ^)/"'
s/""""""""/'"$(repeat_char \")/
}" docs/README.rst docs/map.jinja.rst
# Replace all other instances of TEMPLATE with the regular new formula name
grep --recursive --files-with-matches --exclude-dir=.git TEMPLATE . \
| while read -r filename; do