mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-01-05 20:58:51 +01:00
prettybat: Add support for SVG formatting using prettier
This commit is contained in:
parent
860638715a
commit
54db67408e
@ -30,6 +30,7 @@ See `man bat` for more information.
|
||||
| JSON | [prettier](https://prettier.io/) |
|
||||
| YAML | [prettier](https://prettier.io/) |
|
||||
| HTML | [prettier](https://prettier.io/) |
|
||||
| SVG | [prettier](https://prettier.io/) |
|
||||
| Rust | [rustfmt](https://github.com/rust-lang/rustfmt) |
|
||||
| Bash | [shfmt](https://github.com/mvdan/sh) |
|
||||
| C | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
|
||||
|
@ -32,7 +32,7 @@ formatter_prettier_supports() {
|
||||
.ts | .tsx | \
|
||||
.css | .scss | .sass | \
|
||||
.graphql | .gql | \
|
||||
.html | \
|
||||
.html | .svg | \
|
||||
.json | \
|
||||
.md | \
|
||||
.yml)
|
||||
@ -44,7 +44,14 @@ formatter_prettier_supports() {
|
||||
}
|
||||
|
||||
formatter_prettier_process() {
|
||||
prettier --stdin --stdin-filepath "$1" 2>/dev/null
|
||||
# Rewrite the file extension to hackily support SVG.
|
||||
local file="$1"
|
||||
local fext="$(extname "$file")"
|
||||
case "$fext" in
|
||||
.svg) file="$(basename -- "$file" "$fext").html" ;;
|
||||
esac
|
||||
|
||||
prettier --stdin --stdin-filepath "$file" 2>/dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
@ -130,6 +137,7 @@ map_language_to_extension() {
|
||||
css) ext=".css" ;;
|
||||
scss) ext=".scss" ;;
|
||||
sass) ext=".sass" ;;
|
||||
svg ) ext=".svg" ;;
|
||||
html | htm | shtml | xhtml) ext=".html" ;;
|
||||
json) ext=".json" ;;
|
||||
md | mdown | markdown) ext=".md" ;;
|
||||
@ -222,7 +230,7 @@ process_file() {
|
||||
# shellcheck disable=SC2094 disable=SC2181
|
||||
if [[ "$file" = "-" ]]; then
|
||||
data_raw="$(cat -)"
|
||||
data_formatted="$("formatter_${formatter}_process" "$file" 2>/dev/null <<<"$data_raw")"
|
||||
data_formatted="$("formatter_${formatter}_process" "STDIN${fext}" 2>/dev/null <<<"$data_raw")"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
print_warning "'STDIN': Unable to format with '%s'" "$formatter"
|
||||
|
Loading…
Reference in New Issue
Block a user