mirror of http://git.davidovski.xyz/shblg.git
Add url and image parsing
This commit is contained in:
parent
e13af149ea
commit
e8e91a5025
|
@ -8,7 +8,7 @@ _pre_emph () {
|
||||||
printf "%s_" "${line%%\**}"
|
printf "%s_" "${line%%\**}"
|
||||||
line="${line#*\*}"
|
line="${line#*\*}"
|
||||||
done
|
done
|
||||||
printf "${line}\n"
|
printf "%s\n" "${line}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ _post_emph () {
|
||||||
printf "%s${right}" "${line%%${wrong}*}"
|
printf "%s${right}" "${line%%${wrong}*}"
|
||||||
line="${line#*${wrong}}"
|
line="${line#*${wrong}}"
|
||||||
done
|
done
|
||||||
printf "${line}\n"
|
printf "%s\n" "${line}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,6 @@ _h () {
|
||||||
#
|
#
|
||||||
# p
|
# p
|
||||||
_p () {
|
_p () {
|
||||||
local num=$1
|
|
||||||
empty=true
|
empty=true
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
case "$line" in
|
case "$line" in
|
||||||
|
@ -109,15 +108,60 @@ _p () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# parse links
|
||||||
|
#
|
||||||
|
_a_img () {
|
||||||
|
local open="[" mid="](" close=")"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
next="$line"
|
||||||
|
while [ "$next" != "${next#*$close}" ]; do
|
||||||
|
before="${next%%$open*}"
|
||||||
|
text=${next#*$open} text=${text%%$mid*}
|
||||||
|
url=${next#*$mid} url=${url%%$close*}
|
||||||
|
|
||||||
|
title=${url#* } url=${url%% *}
|
||||||
|
|
||||||
|
[ "$title" != "$url" ] \
|
||||||
|
&& title=" title=$title" \
|
||||||
|
|| title=
|
||||||
|
|
||||||
|
case "$before" in
|
||||||
|
*!) h="%s<img src=\"%s\"%s alt=\"%s\"></img>"
|
||||||
|
before="${before%!}" ;;
|
||||||
|
*) h="%s<a href=\"%s\"%s>%s</a>" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
printf "$h" "$before" "$url" "$title" "$text"
|
||||||
|
|
||||||
|
next="${next#*$close}"
|
||||||
|
done
|
||||||
|
printf "%s\n" "$next";
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse unordered lists
|
||||||
|
#
|
||||||
|
_ul () {
|
||||||
|
}
|
||||||
|
|
||||||
|
# parse ordered lists
|
||||||
|
#
|
||||||
|
_ol () {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# convert the markdown from stdin into html
|
# convert the markdown from stdin into html
|
||||||
#
|
#
|
||||||
md2html () {
|
md2html () {
|
||||||
|
|
||||||
_p \
|
_p \
|
||||||
| _pre_emph \
|
| _pre_emph \
|
||||||
| _emph '__' "<strong>" "</strong>" \
|
| _emph '__' "<strong>" "</strong>" \
|
||||||
| _emph '_' "<em>" "</em>" \
|
| _emph '_' "<em>" "</em>" \
|
||||||
|
| _emph '`' "<code>" "</code>" \
|
||||||
| _post_emph \
|
| _post_emph \
|
||||||
|
| _a_img \
|
||||||
| _h 6 \
|
| _h 6 \
|
||||||
| _h 5 \
|
| _h 5 \
|
||||||
| _h 4 \
|
| _h 4 \
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
This is *italics* this is **bold** this is ***both*** wow
|
This is *italics* this is **bold** this is ***both*** wow
|
||||||
|
|
||||||
so hold tight
|
click [here](http) for stuff and [over here](http12 "my title") for more
|
||||||
|
|
||||||
|
![this is an image](httpsomething)
|
||||||
|
|
||||||
this is a paragraph
|
this is a paragraph
|
||||||
|
|
||||||
haha
|
haha
|
||||||
|
|
Loading…
Reference in New Issue