mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-01-06 13:18:51 +01:00
mdroff: Trim lines before emitting them
This commit is contained in:
parent
655038878b
commit
644c817ba2
@ -125,6 +125,10 @@ mdroff:emit() {
|
|||||||
"mdroff:emit:${type}" "$data" "${@:3}"
|
"mdroff:emit:${type}" "$data" "${@:3}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mdroff:trim() {
|
||||||
|
sed 's/^[[:space:]]*//; s/[[:space:]]*$//' <<< "$1"
|
||||||
|
}
|
||||||
|
|
||||||
mdroff:parseln() {
|
mdroff:parseln() {
|
||||||
MDROFF_ATTR_STRONG=false
|
MDROFF_ATTR_STRONG=false
|
||||||
MDROFF_ATTR_EMPHASIS=false
|
MDROFF_ATTR_EMPHASIS=false
|
||||||
@ -137,7 +141,7 @@ mdroff:parseln() {
|
|||||||
|
|
||||||
while [[ "${#buffer}" -gt 0 ]]; do
|
while [[ "${#buffer}" -gt 0 ]]; do
|
||||||
[[ "$buffer" =~ \*{1,3}|\`|\[([^\]]+)\]\(([^\)]+)\) ]] || {
|
[[ "$buffer" =~ \*{1,3}|\`|\[([^\]]+)\]\(([^\)]+)\) ]] || {
|
||||||
printf "%s\n" "$buffer"
|
printf "%s\n" "$(mdroff:trim "$buffer")"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +254,7 @@ mdroff() {
|
|||||||
# shellcheck disable=SC2206
|
# shellcheck disable=SC2206
|
||||||
IFS='|' raw_cells=($line)
|
IFS='|' raw_cells=($line)
|
||||||
for table_cell in "${raw_cells[@]}"; do
|
for table_cell in "${raw_cells[@]}"; do
|
||||||
cells+=("$(sed 's/^[[:space:]]*//; s/[[:space:]]*$//' <<< "$table_cell")")
|
cells+=("$(mdroff:trim "$table_cell")")
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "${cells[0]}" =~ ^[[:space:]]*-+[[:space:]]*$ ]]; then
|
if [[ "${cells[0]}" =~ ^[[:space:]]*-+[[:space:]]*$ ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user