From a7f45bef3a12fffb6378afdf6df9151fe34e42e8 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 14 Jan 2023 20:03:34 -0600 Subject: Add EL_ESCAPE option --- plugins/el.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/el.sh b/plugins/el.sh index 6d0780a..87eca03 100644 --- a/plugins/el.sh +++ b/plugins/el.sh @@ -2,6 +2,9 @@ ### 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 @@ -12,18 +15,23 @@ el() { # el NAME ARGS... # 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" + _element="$_name" _content="" _process_args=true while test -n "$1"; do case "$1" in - --) if "$_process_args"; then + --) + 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#*=}\"" @@ -40,8 +48,12 @@ el() { # el NAME ARGS... esac shift done - _element="$_element\\>" - printf '%s%s\\\n' "$_element" "$_content" "$_name" + if $EL_ESCAPE; then + fmt='\<%s\>%s\\n' + else + fmt='<%s>%s\n' + fi + printf "$fmt" "$_element" "$_content" "$_name" } ### HTML5 element aliases -- cgit 1.4.1-21-gabe81