about summary refs log tree commit diff stats
path: root/st.sh
blob: 827452629b902031534a952f0d3b16cb8c3d35e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
### st.sh

# utilities
echo()(printf '%s\n' "$*")

handle_input() { # handle_input "$@"
	# handle input --- args or stdin
	test -n "$1" && printf '%s' "$*"
	if read -r first_line
	then echo "$first_line"; cat
	else echo
	fi
}

# authoring commands
nb() { # comment mechanism
	:
}

# html
attr(){ # attr [NAME|VALUE] ATTR_STRING
	case "$1" in
		(name) echo "${2%%=*}" ;;
		(value) echo "${2#*=}" ;;
	esac
}

html_el(){ # el TAG [ATTRS...] [TEXT...] [< INPUT]
	tag="$1"; attrs= ; text=
	shift
	for arg
	do
		case "$arg" in
			(*=*) attrs="$attrs ${arg%%=*}=${arg#*=}"; shift ;;
			(*) break ;;
		esac
	done

	printf '<%s%s>%s' "$tag" "$attrs"
	handle_input "$@" | sed '$s,$,</'"$tag"'>,'
}

alias p='html_el p'
alias a='html_el a'
alias h1='html_el h1'
alias blockquote='html_el blockquote'
alias bq=blockquote