mirror of
http://git.davidovski.xyz/shblg.git
synced 2024-08-15 00:43:48 +00:00
Add blockquotes
This commit is contained in:
parent
6bc6d5fb6b
commit
1eac038e14
2 changed files with 65 additions and 8 deletions
|
@ -86,8 +86,11 @@ _p () {
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
case "$line" in
|
case "$line" in
|
||||||
"#"*|">"*|'``'*|'<'*'>'*)
|
"#"*|">"*|'``'*|'<'*'>'*)
|
||||||
$empty &&
|
$empty || {
|
||||||
printf "%s\n" "$line"
|
printf "</p>\n"
|
||||||
|
empty=true
|
||||||
|
}
|
||||||
|
printf "%s\n" "$line"
|
||||||
;;
|
;;
|
||||||
"")
|
"")
|
||||||
$empty || {
|
$empty || {
|
||||||
|
@ -97,8 +100,8 @@ _p () {
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
$empty &&
|
$empty &&
|
||||||
printf "<p>%s " "$line" ||
|
printf "<p>\n%s\n " "$line" ||
|
||||||
printf "%s " "$line"
|
printf "%s\n " "$line"
|
||||||
|
|
||||||
empty=false ;;
|
empty=false ;;
|
||||||
esac
|
esac
|
||||||
|
@ -146,7 +149,8 @@ _a_img () {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# get indentation level of a line
|
||||||
|
#
|
||||||
_get_indent () {
|
_get_indent () {
|
||||||
indent=0
|
indent=0
|
||||||
l="$*"
|
l="$*"
|
||||||
|
@ -244,15 +248,54 @@ _ol () {
|
||||||
|
|
||||||
# parse quotes
|
# parse quotes
|
||||||
#
|
#
|
||||||
#_quote () {
|
_blockquote () {
|
||||||
#}
|
local level=0
|
||||||
|
while IFS= read -r line; do
|
||||||
|
set - $line
|
||||||
|
case "$1" in
|
||||||
|
">"*)
|
||||||
|
indent=0
|
||||||
|
while [ "$line" ]; do
|
||||||
|
c="${line%*${line#?}}"
|
||||||
|
case "$c" in
|
||||||
|
">") indent=$((indent+1)) ;;
|
||||||
|
" "*)
|
||||||
|
line="${line#?}"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
line="${line#?}"
|
||||||
|
done
|
||||||
|
|
||||||
|
[ "$indent" -gt "$level" ] &&
|
||||||
|
printf "<blockquote>\n"
|
||||||
|
[ "$indent" -lt "$level" ] &&
|
||||||
|
printf "</blockquote>\n"
|
||||||
|
level="$indent"
|
||||||
|
printf "%s\n" "$line"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "%s\n" "$line"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
[ "$indent" -lt "$level" ] &&
|
||||||
|
printf "</blockquote>\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
_html () {
|
||||||
|
printf "<!DOCTYPE html>\n"
|
||||||
|
cat
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# convert the markdown from stdin into html
|
# convert the markdown from stdin into html
|
||||||
#
|
#
|
||||||
md2html () {
|
md2html () {
|
||||||
|
|
||||||
|
# the order of these somewhat matters
|
||||||
_pre_emph \
|
_pre_emph \
|
||||||
|
| _blockquote \
|
||||||
| _ul \
|
| _ul \
|
||||||
| _ol \
|
| _ol \
|
||||||
| _p \
|
| _p \
|
||||||
|
@ -266,7 +309,8 @@ md2html () {
|
||||||
| _h 4 \
|
| _h 4 \
|
||||||
| _h 3 \
|
| _h 3 \
|
||||||
| _h 2 \
|
| _h 2 \
|
||||||
| _h 1
|
| _h 1 \
|
||||||
|
| _html
|
||||||
}
|
}
|
||||||
|
|
||||||
md2html
|
md2html
|
||||||
|
|
13
src/test.md
13
src/test.md
|
@ -8,6 +8,19 @@ click [here](http) for stuff and [over here](http12 "my title") for more
|
||||||
|
|
||||||
this is a paragraph
|
this is a paragraph
|
||||||
|
|
||||||
|
> this is a quote hi
|
||||||
|
|
||||||
|
ok that was a quote
|
||||||
|
|
||||||
|
> this quote has a list inside i
|
||||||
|
> - this is a list in a quote
|
||||||
|
> - it was quoted
|
||||||
|
>
|
||||||
|
> and also there is another quote;
|
||||||
|
>> Hi i am a quote
|
||||||
|
>
|
||||||
|
|
||||||
|
|
||||||
haha
|
haha
|
||||||
|
|
||||||
- this is a list
|
- this is a list
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue