From 6b63dad736d44ef0e61f4ca1aa95e07430b89af3 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 9 May 2024 22:28:47 -0500 Subject: Finish shell impl This version includes - customizable format specifiers for all elements - line and buffer filtering, which makes all sorts of things possible - and more! --- jimmy.sh | 137 --------------------------------------------------------------- 1 file changed, 137 deletions(-) delete mode 100755 jimmy.sh (limited to 'jimmy.sh') diff --git a/jimmy.sh b/jimmy.sh deleted file mode 100755 index f039f4f..0000000 --- a/jimmy.sh +++ /dev/null @@ -1,137 +0,0 @@ -#!/bin/sh - -BLOCK= -BUFFER= - -process() { - while read -r LINE - do - if test "$BLOCK" = verbatim - then - printf '%s\n' "$LINE" - continue - fi - - set -- $LINE - - case "$LINE" in - ('```') - if test "$BLOCK" = verbatim - then BLOCK= - else BLOCK=verbatim - fi - ;; - ('') - if test "$BLOCK" = verbatim - then bufpush $'\n' - else bufclose - fi - ;; - ('=>'*) link "$@" ;; - ('#'*) header "$@" ;; - ('*'*) shift; blknew list "$*" ;; - ('>'*) shift; blknew quote "$*" ;; - (*) shift; blknew paragraph "$*" ;; - esac - done - bufclose -} - -blknew() { - test "$BLOCK" = "$1" || bufclose - bufpush "$(printf "$(eval echo "\$format_$BLOCK")" "$@")" - BLOCK="$1" -} - -bufclose() { - if test -z "$BLOCK" - then "$COLLAPSE_BLANKS" && return - else newline; return - fi - - # blockp "$BLOCK" || return - # fillp $BLOCK && buffill "$(fillp $BLOCK)" - - # TODO: escape shit - - printf '%s%s%s\n' \ - "$(echo eval "\$opener_$BLOCK")" \ - "$BUFFER" \ - "$(echo eval "\$closer_$BLOCK")" - - BLOCK= -} - -buffill() { # buffill WIDTH - if test $1 -lt 0 - then BUFFER="$(printf '%s\n' "$BUFFER" | tr '\n' ' ')" - else - out= - nline=0 - printf '%s\n' "$BUFFER" | sed 's/[ \t]\+/\n/g' | - while read -r word - do - if test $((nline + ${#word})) -ge "$1" - then - out="${out}"${out:+$'\n'}"${word}" - nline=${#word} - else - out="${out}${out:+ }${word}" - nline=$((nline + ${#word} + 1)) - fi - done - BUFFER="$out" - fi -} - -bufpush() { BUFFER="${BUFFER}$@"; } - -fillp() { - : -} - -header() { - bufclose - lvl=${#1}; shift - bufpush "$(printf "$(eval echo "\$format_h$lvl")" "$*")" - BLOCK=header -} - -link() { - url="$2"; shift 2 - if test "$BLOCK" = paragraph #&& ! blockp link - then bufpush "$(printf "$format_link" "$url" "$*")" - else blknew linklist "$url" "$*" - fi -} - -newline() { printf '\n'; } - -html() { - format_link='%s\n' - format_h1='

%s

\n' - format_h2='

%s

\n' - format_h3='

%s

\n' - opener_verbatim='
'
-	closer_verbatim='
\n' - format_verbatim='%s\n' - opener_paragraph='

' - closer_paragraph='

\n' - format_paragraph='%s\n' - opener_quote='
' - closer_quote='
\n' - format_quote='%s\n' - opener_list='\n' - format_list='
  • %s
  • ' - opener_linklist='' - format_linklist="$(printf "$format_list" "$format_link")" -} - -main() { - html - process "$@" -} - -main "$@" -- cgit 1.4.1-21-gabe81