From f8b8b0a7cad96c648c896fa6eb660fdb988dfdb2 Mon Sep 17 00:00:00 2001
From: davidovski
\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\n" + *!) h="%s\n%s\n" before="${before%!}" ;; *) h="%s\n%s\n%s\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 "
" "
# 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
--
cgit v1.2.1