# el.sh --- insert html elements using sh ### Code: ## Escape < and > with backslashes. EL_ESCAPE=true el() { # el NAME ARGS... ## Create an HTML element named NAME using ARGS. # Any ARGS that contain an equals sign will be made into attributes of the # element, until the special argument '--' which will stop attribute # processing. While some nesting is possible with 'el', the way bash # expansion works it's not great. # # No validation is done on any arguments in this function. It could create # something that looks vaguely like an HTML element but isn't valid. _name="$1" shift || return 1 # Require at least an element name _element="$_name" _content="" _process_args=true while test -n "$1"; do case "$1" in --) if "$_process_args"; then _process_args=false else _content="$_content${_content:+ }$1" fi ;; '\<'*) _process_args=false _content="$_content${_content:+ }$1" ;; *=*) if "$_process_args"; then _element="$_element ${1%%=*}=\"${1#*=}\"" else _content="$_content${_content:+ }$1" fi ;; *) if "$_process_args"; then _process_args=false fi _content="$_content${_content:+ }$1" ;; esac shift done if $EL_ESCAPE; then fmt='\<%s\>%s\\n' else fmt='<%s>%s\n' fi printf "$fmt" "$_element" "$_content" "$_name" } ### HTML5 element aliases ## These come from https://developer.mozilla.org/en-US/docs/Web/HTML/Element # To avoid clobbering the shell's namespace, a prefix is used. Change this # variable when sourcing el.sh in order to change or disable the prefix. E.g.: # $ EL_PREFIX= . ./el.sh # $ EL_PREFIX=HTML . ./el.sh : "${EL_PREFIX:=_}" for e in \ html \ base \ head \ link \ meta \ style \ title \ body \ address \ article \ aside \ footer \ header \ h1 \ h2 \ h3 \ h4 \ h5 \ h6 \ main \ nav \ section \ blockquote \ dd \ div \ dl \ dt \ figcaption \ figure \ hr \ li \ menu \ ol \ p \ pre \ ul \ a \ abbr \ b \ bdi \ bdo \ br \ cite \ code \ data \ dfn \ em \ i \ kbd \ mark \ q \ rp \ rt \ ruby \ s \ samp \ small \ span \ strong \ sub \ sup \ time \ u \ var \ wbr \ area \ audio \ img \ map \ track \ video \ embed \ iframe \ object \ picture \ portal \ source \ svg \ math \ canvas \ noscript \ script \ del \ ins \ caption \ col \ colgroup \ table \ tbody \ td \ tfoot \ th \ thead \ tr \ button \ datalist \ fieldset \ form \ input \ label \ legend \ meter \ optgroup \ option \ output \ progress \ select \ textarea \ details \ dialog \ summary \ slot \ template \ acronym \ applet \ bgsound \ big \ blink \ center \ content \ dir \ font \ frame \ frameset \ image \ keygen \ marquee \ menuitem \ nobr \ noembed \ noframes \ param \ plaintext \ rb \ rtc \ shadow \ spacer \ strike \ tt \ xmp; do eval "alias $EL_PREFIX$e='el $e'" done # el.sh ends here