]> git.plutz.net Git - cgilite/blobdiff - html-sh.sed
introduce . as stop sign to prevent parsing text as attributes
[cgilite] / html-sh.sed
index d1c70b8cc6ae65ed0083af3b295edd8d47cca16e..16aeb9a44e907814b5865fb9887fbe9833f450d8 100755 (executable)
@@ -1,4 +1,12 @@
-#!/bin/sed -nrf
+#!/bin/sed -nEf
+
+:Escapes
+s,\\\\,\\,g; s,\\&,\&,g;
+s,\\<,\&lt;,g; s,\\>,\&gt;,g;
+s,\\",\&quot;,g; s,\\',\&apos;,g;
+s,\\\[,\&#91;,g; s,\\\],\&#93;,g;
+s,\\\.,\&#46;,g; s,\\#,\&#35;,g;
+s,\\,,g;
 
 :CommentHandle
 x; /^<\/!-->/{
@@ -40,19 +48,22 @@ t tagopen;
 G; h; s;^[^\n]*\n+;;; x; s;\n.*$;;;
 
 :attribs
+s;(<[^/][^>]*)>[ \t]*\.[ \t];\1>;g; t attEnd;
 s;class="([^>]+)>[ \t]*\.([^< \t]+);class="\2 \1>;g; t attribs;
 s;(<[^/][^>]*)>[ \t]*\.([^< \t]+);\1 class="\2">;g;
 s;(<[^/][^>]*)>[ \t]*#([^< \t]+);\1 id="\2">;g;
 s;(<[^/][^>]*)>[ \t]*([^ \t=<]+=("[^"]*"|'[^']*'|[^< \t]*));\1 \2>;g;
 t attribs;
-s;(<input ([^>]+ )?type=(radio|"radio"|'radio')( [^>]+)?)>[ \t]*checked;\1 checked="checked">;g;
-s;(<input ([^>]+ )?type=(checkbox|"checkbox"|'checkbox')( [^>]+)?)>[ \t]*checked;\1 checked="checked">;g;
+s;(<input ([^>]+ )?type=(radio|"radio"|'radio')( [^>]+)?)>[ \t]*(checked|selected);\1 checked="checked">;g;
+s;(<input ([^>]+ )?type=(checkbox|"checkbox"|'checkbox')( [^>]+)?)>[ \t]*(checked|selected);\1 checked="checked">;g;
 s;(<option( [^>]+)?)>[ \t]*(checked|selected);\1 selected="selected">;g;
 s;(<select( [^>]+)?)>[ \t]*multiple;\1 multiple="multiple">;g;
 t attribs;
+:attEnd
 
 s;(<[^/][^>]*>)[ \t]*;\1;g;
-s;(<[^/][^>]*)>[ \t]*</[^>]+>;\1/>;g;
+# s;(<[^/][^>]*)>[ \t]*</[^>]+>;\1/>;g;
+s;(<(br|hr|img|input|link|meta|area|base|col|command|embed|keygen|param|source|track|wbr)[^>]*)>[ \t]*</\1>;\1>;g;
 
 s;<!-->;<!--;;