about summary refs log tree commit diff stats
path: root/etlib.sh
blob: bdf1846256629b69103d6e69558d17ebd2140d81 (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
# etlib

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

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"
	test -n "$1" && printf '%s' "$*"
	if read -r fl
	then echo "$fl"; cat
	else echo
	fi |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