diff options
author | davidovski <david@davidovski.xyz> | 2023-12-31 01:25:56 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-12-31 01:25:56 +0000 |
commit | f8b8b0a7cad96c648c896fa6eb660fdb988dfdb2 (patch) | |
tree | ef18e1c4a5c13c19906f494789e38a2573d6c2ff | |
parent | fa405f8fbff5ad6e73b0dfa887165986e037d1fd (diff) |
reformat
-rwxr-xr-x | install.sh | 6 | ||||
-rwxr-xr-x | src/md2html.sh | 56 | ||||
-rwxr-xr-x | src/shblg.sh | 24 |
3 files changed, 42 insertions, 44 deletions
@@ -2,7 +2,7 @@ # installs m2html and shblg to the system path -PREFIX=${PREFIX:-/usr} +PREFIX="${PREFIX:-/usr}" -install -m755 src/md2html.sh ${PREFIX}/bin/md2html -install -m755 src/shblg.sh ${PREFIX}/bin/shblg +install -m755 src/md2html.sh "${PREFIX}/bin/md2html" +install -m755 src/shblg.sh "${PREFIX}/bin/shblg" diff --git a/src/md2html.sh b/src/md2html.sh index 54ed1fe..e249ee0 100755 --- a/src/md2html.sh +++ b/src/md2html.sh @@ -25,7 +25,6 @@ _pre_strip () { while IFS= read -r line; do set -- $line [ "$*" ] && { - local l c l="$line" line= while [ "$l" != "${l#?}" ]; do @@ -63,7 +62,7 @@ _post_emph () { case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; esac # TODO: avoid this problem entirely? - local wrong="</strong></em>" right="</em></strong>" + wrong="</strong></em>" right="</em></strong>" while [ "$line" != "${line%%${wrong}*}" ]; do printf "%s${right}" "${line%%${wrong}*}" @@ -78,8 +77,9 @@ _post_emph () { # emph [bound] <lefttag> <righttag> # _emph () { - local bound="$1" - local lefttag="$2" righttag="$3" + bound="$1" + lefttag="$2" + righttag="$3" while IFS= read -r line; do case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; esac @@ -103,7 +103,7 @@ _emph () { # h [heading no.] # _h () { - local num=$1 + num=$1 while IFS= read -r line; do case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; esac s= @@ -128,7 +128,7 @@ _h () { # parse paragraphs # _p () { - local empty=true + empty=true while IFS= read -r line; do case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; @@ -139,13 +139,13 @@ _p () { } printf "%s\n" "$line" ;; - "") + "") $empty || { printf "</p>\n" - empty=true + empty=true } ;; - *) + *) $empty && printf "<p>\n%s\n" "$line" || printf "%s\n" "$line" @@ -167,9 +167,9 @@ _p () { # parse links # _a_img () { - local open="[" mid="](" close=")" + open="[" mid="](" close=")" while IFS= read -r line; do - case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; esac + case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue; esac next="$line" while [ "$next" != "${next#*$close}" ]; do case "$next" in @@ -187,7 +187,7 @@ _a_img () { || title= case "$before" in - *!) h="%s\n%s<img src=\"%s\"%s alt=\"%s\"></img>\n" + *!) h="%s\n%s<img src=\"%s\"%s alt=\"%s\"></img>\n" before="${before%!}" ;; *) h="%s\n%s<a href=\"%s\"%s>\n%s</a>\n" ;; esac @@ -211,12 +211,12 @@ _get_indent () { " ") indent=$((indent+1)) ;; *) l="${l#?}" - break + break ;; esac l="${l#?}" done - printf "$indent" + printf "%s" "$indent" } # print a string x times @@ -225,7 +225,7 @@ _get_indent () { print_x () { x=$1; shift until [ "$((x=x-1))" -lt "0" ]; do - printf "$*" + printf "%s" "$*" done } @@ -233,8 +233,8 @@ print_x () { # parse unordered lists # _ul () { - local indent_level=-1 - local to_close=0 + indent_level=-1 + to_close=0 while IFS= read -r line; do case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; esac set -- $line @@ -254,7 +254,7 @@ _ul () { printf "<li>%s</li>\n" "${line#*$1 }" ;; - *) + *) [ $to_close -gt 0 ] && { print_x $to_close "</ul>\n" to_close=0 @@ -270,12 +270,12 @@ _ul () { # parse ordered lists # _ol () { - local indent_level=-1 - local to_close=0 + indent_level=-1 + to_close=0 while IFS= read -r line; do case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; esac set -- $line - case "$1" in + case "$1" in *.|*\)) indent=$(_get_indent "$line") @@ -284,14 +284,14 @@ _ol () { to_close=$((to_close+1)) } [ "$indent_level" -gt "$indent" ] && { - printf "</ol>\n" + printf "</ol>\n" to_close=$((to_close-1)) } indent_level=$indent printf "<li>%s</li>\n" "${line#*$1 }" ;; - *) + *) [ $to_close -gt 0 ] && { print_x $to_close "</ol>\n" to_close=0 @@ -315,7 +315,7 @@ $ESC_SEQ<code>" "</code> # parse multiline codeblocks # _code () { - local codeblock=false content=true + codeblock=false content=true while IFS= read -r line; do case "$line" in " "*) @@ -351,7 +351,7 @@ _code () { # parse quotes # _blockquote () { - local indent_level=0 + indent_level=0 while IFS= read -r line; do case "$line" in "$ESC_SEQ"*) printf "%s\n" "$line" && continue;; esac set - $line @@ -389,8 +389,8 @@ _html () { done } -# remove all unecessary newlines -# +# remove all unecessary newlines +# _squash () { while IFS= read -r line; do case "$line" in @@ -433,4 +433,4 @@ md2html () { [ -z "$*" ] \ && md2html \ - || cat "$1" | md2html + || md2html < "$1" diff --git a/src/shblg.sh b/src/shblg.sh index 8637bcd..61ef7db 100755 --- a/src/shblg.sh +++ b/src/shblg.sh @@ -11,23 +11,22 @@ usage () { while getopts ":o:i:h" opt; do case "$opt" in o) - OUTPUT_DIR=$OPTARG/ - mkdir -p $OUTPUT_DIR - OUTPUT_DIR=$(realpath $OUTPUT_DIR) + OUTPUT_DIR="$OPTARG/" + mkdir -p "$OUTPUT_DIR" + OUTPUT_DIR="$(realpath "$OUTPUT_DIR")" ;; i) - INPUT_DIR=$(realpath $OPTARG) + INPUT_DIR="$(realpath "$OPTARG")" ;; - h) - usage + *) usage ;; esac done # process a file to process () { - path="${1#$INPUT_DIR}" - dirpath="${1%${1##*/}}" + path="${1#"$INPUT_DIR"}" + dirpath="${1%"${1##*/}"}" out_file="${OUTPUT_DIR}${path}" printf "%s ...\n" "$path" @@ -36,15 +35,14 @@ process () { mkdir -p "$out_file" for f in "$1"/*; do process "$f" - done + done return 0 - } || [ -x "$1" ] && { + } || [ -x "$1" ] && ( # execute the file - cd $dirpath + cd "$dirpath" "$1" > "${out_file}" - cd - return 0 - } || { + ) || { # just copy the file as is cp "$1" "$out_file" return 0 |