mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 11:47:43 +02:00
mdroff: Fix text being trimmed incorrectly
This commit is contained in:
parent
33e0c168e0
commit
ef0356a2d8
15
mdroff.sh
15
mdroff.sh
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user