mdroff: Fix text being trimmed incorrectly

This commit is contained in:
Ethan P 2021-08-21 16:02:48 -07:00
parent 33e0c168e0
commit ef0356a2d8
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA

View File

@ -115,6 +115,11 @@ mdroff:emit:table_row() {
printf "%s\n" "${row:1}" printf "%s\n" "${row:1}"
} }
mdroff:emit:text() {
local text="$1"
printf "%s" "$text"
}
mdroff:emit() { mdroff:emit() {
local type="$1" local type="$1"
local data="$2" local data="$2"
@ -131,6 +136,11 @@ mdroff:emit() {
"mdroff:emit:${type}" "$data" "${@:3}" "mdroff:emit:${type}" "$data" "${@:3}"
} }
mdroff:trim_right() {
# shellcheck disable=SC2001
sed 's/[[:space:]]*$//' <<< "$1"
}
mdroff:trim() { mdroff:trim() {
sed 's/^[[:space:]]*//; s/[[:space:]]*$//' <<< "$1" sed 's/^[[:space:]]*//; s/[[:space:]]*$//' <<< "$1"
} }
@ -147,7 +157,8 @@ mdroff:parseln() {
while [[ "${#buffer}" -gt 0 ]]; do while [[ "${#buffer}" -gt 0 ]]; do
[[ "$buffer" =~ \*{1,3}|\`|\[([^\]]+)\]\(([^\)]+)\) ]] || { [[ "$buffer" =~ \*{1,3}|\`|\[([^\]]+)\]\(([^\)]+)\) ]] || {
printf "%s\n" "$(mdroff:trim "$buffer")" mdroff:emit text "$(mdroff:trim_right "$buffer")"
mdroff:emit text $'\n'
return return
} }
@ -157,7 +168,7 @@ mdroff:parseln() {
before="${buffer:0:$pos}" before="${buffer:0:$pos}"
buffer="${buffer:$(($pos + ${#found}))}" buffer="${buffer:$(($pos + ${#found}))}"
printf "%s" "$before" mdroff:emit text "$before"
case "$found" in case "$found" in
'***') '***')
if "$MDROFF_ATTR_STRONG" && "$MDROFF_ATTR_EMPHASIS"; then if "$MDROFF_ATTR_STRONG" && "$MDROFF_ATTR_EMPHASIS"; then