]> git.plutz.net Git - cgilite/blob - html-sh.sed
Merge branch 'master' of git.plutz.net:cgilite
[cgilite] / html-sh.sed
1 #!/bin/sed -nrf
2
3 :CommentHandle
4 x; /^<\/!-->/{
5   x; /--]/{
6     H; s;^(.*)--].*$;\1-->;p;
7     g; s;^.*--]([^\n]*)$;\1;
8     x; s;^</!-->\n(.*)\n[^\n]*$;\1;; x;
9     bCommentEnd
10   }
11   p; b;
12 }
13 x;
14 :CommentEnd
15
16 :shortcuts
17 s;\[hidden[ \t]+"([^"]*)"[ \t]+"([^"]*)";[input type="hidden" name="\1" value="\2";g;
18 s;\[checkbox[ \t]+"([^"]*)"[ \t]+"([^"]*)";[input type="checkbox" name="\1" value="\2";g;
19 s;\[radio[ \t]+"([^"]*)"[ \t]+"([^"]*)";[input type="radio" name="\1" value="\2";g;
20 s;\[submit[ \t]+"([^"]*)"[ \t]+"([^"]*)";[button type="submit" name="\1" value="\2";g;
21 s;\[a[ \t]+"([^"]*)";[a href="\1";g;
22 s;\[img[ \t]+"([^"]*)"[ \t]+"([^"]*)";[img src="\1" alt="\2";g;
23
24 s;\[!([^]\[]*)\];<!\1>;g;
25 s;\[!--([^]\[]*)--\];<!--\1-->;g;
26
27 :tags
28 s;\[([^]\[< \t]+)([^]\[]*)\];<\1>\2</\1>;g;
29 t tags;
30
31 G;
32 :tagclose
33 s;^([^]\n]*)\]([^\n]*)\n([^\n]+);\1\3\2;
34 t tagclose;
35 h; s;^([^\n]*)\n;;; x; s;\n.*$;;;
36
37 :tagopen
38 s;^([^\[\n]*)\[([^]\[< \t\n]+)([^\n]*);\1<\2>\3\n</\2>;
39 t tagopen;
40 G; h; s;^[^\n]*\n+;;; x; s;\n.*$;;;
41
42 :attribs
43 s;class="([^>]+)>[ \t]*\.([^< \t]+);class="\2 \1>;g; t attribs;
44 s;(<[^/][^>]*)>[ \t]*\.([^< \t]+);\1 class="\2">;g;
45 s;(<[^/][^>]*)>[ \t]*#([^< \t]+);\1 id="\2">;g;
46 s;(<[^/][^>]*)>[ \t]*([^ \t=<]+=("[^"]*"|'[^']*'|[^< \t]*));\1 \2>;g;
47 t attribs;
48 s;(<input ([^>]+ )?type=(radio|"radio"|'radio')( [^>]+)?)>[ \t]*(checked|selected);\1 checked="checked">;g;
49 s;(<input ([^>]+ )?type=(checkbox|"checkbox"|'checkbox')( [^>]+)?)>[ \t]*(checked|selected);\1 checked="checked">;g;
50 s;(<option( [^>]+)?)>[ \t]*(checked|selected);\1 selected="selected">;g;
51 s;(<select( [^>]+)?)>[ \t]*multiple;\1 multiple="multiple">;g;
52 t attribs;
53
54 s;(<[^/][^>]*>)[ \t]*;\1;g;
55 s;(<[^/][^>]*)>[ \t]*</[^>]+>;\1/>;g;
56
57 s;<!-->;<!--;;
58
59 p; ${g; s;\n+;;g; p;}