about summary refs log tree commit diff stats
path: root/plugins/el.sh
blob: 87eca0353868edd6c0c02b6640c71d48f506b4d9 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# 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\</%s\>\n'
    else
	fmt='<%s>%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