shithub: werc

Download patch

ref: 56b994b4aa2cb82863a442abec5076d9466880e5
parent: a1eb9e2416d8c696426da3005385a0c1346c560c
author: uriel <uriel@engel.se.cat-v.org>
date: Sat Dec 20 17:56:49 EST 2008

New html_handler that replaces gnu/sed with awk by sqweek, sorry for taking so long and thanks!

--- a/bin/werc.rc
+++ b/bin/werc.rc
@@ -79,7 +79,12 @@
 fn tpl_handler { template $1 }
 
 fn html_handler {
-    cat $1 | /bin/sed '0,/<[Bb][Oo][Dd][Yy][^>]*>/d; /<\/[Bb][Oo][Dd][Yy]>/,$d' 
+    # body states: 0 = no <body> found, 2 = after <body>, 1 = after <body></body>, -1 = after </body>
+    awk 'gsub(".*<[Bb][Oo][Dd][Yy][^>]*>", "") > 0 {body=2}
+        gsub("</ *[Bb][Oo][Dd][Yy][^>]*>.*", "") > 0 {print; body=body-1}
+        body==2 {print}
+        body==0 {buf=buf "\n" $0}
+        END {if(body<=0) {print buf}}' < $1
 }
 
 fn txt_handler {