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