Skip to content

Commit

Permalink
fix(convert-formula.sh): fix reST underlining during conversion
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dafyddj committed Aug 18, 2021
1 parent 84cb63f commit 11068af
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions bin/convert-formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ sedi() {
fi
}

repeat_char() {
printf %"${NEW_NAME_LENGTH}"s | tr " " "$1"
}

args() {
if [ $# -ne 1 ]; then
usage
exit 1
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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 11068af

Please sign in to comment.