diff options
author | Case Duckworth | 2023-01-14 20:03:34 -0600 |
---|---|---|
committer | Case Duckworth | 2023-01-14 20:03:34 -0600 |
commit | a7f45bef3a12fffb6378afdf6df9151fe34e42e8 (patch) | |
tree | 142842691a70b2e06a5f1305b1bba9bcd9d83ee4 /plugins | |
parent | Whitespace (diff) | |
download | vienna-a7f45bef3a12fffb6378afdf6df9151fe34e42e8.tar.gz vienna-a7f45bef3a12fffb6378afdf6df9151fe34e42e8.zip |
Add EL_ESCAPE option
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/el.sh | 20 |
1 files 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 @@ | |||
2 | 2 | ||
3 | ### Code: | 3 | ### Code: |
4 | 4 | ||
5 | ## Escape < and > with backslashes. | ||
6 | EL_ESCAPE=true | ||
7 | |||
5 | el() { # el NAME ARGS... | 8 | el() { # el NAME ARGS... |
6 | ## Create an HTML element named NAME using ARGS. | 9 | ## Create an HTML element named NAME using ARGS. |
7 | # Any ARGS that contain an equals sign will be made into attributes of the | 10 | # Any ARGS that contain an equals sign will be made into attributes of the |
@@ -12,18 +15,23 @@ el() { # el NAME ARGS... | |||
12 | # No validation is done on any arguments in this function. It could create | 15 | # No validation is done on any arguments in this function. It could create |
13 | # something that looks vaguely like an HTML element but isn't valid. | 16 | # something that looks vaguely like an HTML element but isn't valid. |
14 | _name="$1"; shift || return 1 # Require at least an element name | 17 | _name="$1"; shift || return 1 # Require at least an element name |
15 | _element="\\<$_name" | 18 | _element="$_name" |
16 | _content="" | 19 | _content="" |
17 | _process_args=true | 20 | _process_args=true |
18 | 21 | ||
19 | while test -n "$1"; do | 22 | while test -n "$1"; do |
20 | case "$1" in | 23 | case "$1" in |
21 | --) if "$_process_args"; then | 24 | --) |
25 | if "$_process_args"; then | ||
22 | _process_args=false | 26 | _process_args=false |
23 | else | 27 | else |
24 | _content="$_content${_content:+ }$1" | 28 | _content="$_content${_content:+ }$1" |
25 | fi | 29 | fi |
26 | ;; | 30 | ;; |
31 | '\<'*) | ||
32 | _process_args=false | ||
33 | _content="$_content${_content:+ }$1" | ||
34 | ;; | ||
27 | *=*) | 35 | *=*) |
28 | if "$_process_args"; then | 36 | if "$_process_args"; then |
29 | _element="$_element ${1%%=*}=\"${1#*=}\"" | 37 | _element="$_element ${1%%=*}=\"${1#*=}\"" |
@@ -40,8 +48,12 @@ el() { # el NAME ARGS... | |||
40 | esac | 48 | esac |
41 | shift | 49 | shift |
42 | done | 50 | done |
43 | _element="$_element\\>" | 51 | if $EL_ESCAPE; then |
44 | printf '%s%s\\</%s\\>\n' "$_element" "$_content" "$_name" | 52 | fmt='\<%s\>%s\</%s\>\n' |
53 | else | ||
54 | fmt='<%s>%s</%s>\n' | ||
55 | fi | ||
56 | printf "$fmt" "$_element" "$_content" "$_name" | ||
45 | } | 57 | } |
46 | 58 | ||
47 | ### HTML5 element aliases | 59 | ### HTML5 element aliases |