mirror of http://git.davidovski.xyz/shblg.git
Parse ordered lists and unordered lists
This commit is contained in:
parent
7bcc93b621
commit
b1ffc4b5ba
|
@ -110,8 +110,8 @@ _p () {
|
|||
|
||||
# parse ref-style links
|
||||
#
|
||||
_ref () {
|
||||
}
|
||||
#_ref () {
|
||||
#}
|
||||
|
||||
# parse links
|
||||
#
|
||||
|
@ -144,25 +144,106 @@ _a_img () {
|
|||
done
|
||||
}
|
||||
|
||||
|
||||
_get_indent () {
|
||||
indent=0
|
||||
l="$*"
|
||||
while [ "$l" ]; do
|
||||
c="${l%*${l#?}}"
|
||||
case "$c" in
|
||||
" ") indent=$((indent+1)) ;;
|
||||
*)
|
||||
l="${l#?}"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
l="${l#?}"
|
||||
done
|
||||
printf "$indent"
|
||||
}
|
||||
|
||||
|
||||
# parse unordered lists
|
||||
#
|
||||
_ul () {
|
||||
local list=false
|
||||
local indent_level=0
|
||||
while IFS= read -r line; do
|
||||
set -- $line
|
||||
case "$1" in
|
||||
"-"|"_"|"+")
|
||||
indent=$(_get_indent "$line")
|
||||
|
||||
$list || {
|
||||
list=true
|
||||
printf "<ul>\n"
|
||||
}
|
||||
|
||||
[ "$indent_level" -lt "$indent" ] \
|
||||
&& printf "<ul>\n"
|
||||
[ "$indent_level" -gt "$indent" ] \
|
||||
&& printf "</ul>\n"
|
||||
indent_level=$indent
|
||||
|
||||
printf "<li>%s</li>\n" "${line#*$1 }"
|
||||
;;
|
||||
*)
|
||||
$list && {
|
||||
printf "</ul>"
|
||||
list=false
|
||||
}
|
||||
printf "%s\n" "$line"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
$list && printf "</ul>\n"
|
||||
}
|
||||
|
||||
# parse ordered lists
|
||||
#
|
||||
_ol () {
|
||||
local list=false
|
||||
local indent_level=0
|
||||
while IFS= read -r line; do
|
||||
set -- $line
|
||||
case "$1" in
|
||||
*.|*\))
|
||||
indent=$(_get_indent "$line")
|
||||
|
||||
$list || {
|
||||
list=true
|
||||
printf "<ol>\n"
|
||||
}
|
||||
|
||||
[ "$indent_level" -lt "$indent" ] \
|
||||
&& printf "<ol>\n"
|
||||
[ "$indent_level" -gt "$indent" ] \
|
||||
&& printf "</ol>\n"
|
||||
indent_level=$indent
|
||||
|
||||
printf "<li>%s</li>\n" "${line#*$1 }"
|
||||
;;
|
||||
*)
|
||||
$list && {
|
||||
printf "</ol>"
|
||||
list=false
|
||||
}
|
||||
printf "%s\n" "$line"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
$list && printf "</ol>\n"
|
||||
}
|
||||
|
||||
# parse mutliline codeblocks
|
||||
#
|
||||
_code () {
|
||||
}
|
||||
#_code () {
|
||||
#}
|
||||
|
||||
# parse quotes
|
||||
#
|
||||
_quote () {
|
||||
}
|
||||
#_quote () {
|
||||
#}
|
||||
|
||||
|
||||
# convert the markdown from stdin into html
|
||||
|
@ -171,6 +252,8 @@ md2html () {
|
|||
|
||||
_p \
|
||||
| _pre_emph \
|
||||
| _ul \
|
||||
| _ol \
|
||||
| _emph '__' "<strong>" "</strong>" \
|
||||
| _emph '_' "<em>" "</em>" \
|
||||
| _emph '`' "<code>" "</code>" \
|
||||
|
|
19
src/test.md
19
src/test.md
|
@ -9,3 +9,22 @@ click [here](http) for stuff and [over here](http12 "my title") for more
|
|||
this is a paragraph
|
||||
|
||||
haha
|
||||
|
||||
- this is a list
|
||||
- of items
|
||||
- please dont
|
||||
- break
|
||||
|
||||
|
||||
* star list
|
||||
* this is a star
|
||||
|
||||
+ plus now wow
|
||||
+ plus wow so cool
|
||||
|
||||
1. hello
|
||||
2. world
|
||||
3. lOL
|
||||
|
||||
|
||||
ok that worked?
|
||||
|
|
Loading…
Reference in New Issue