summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-08-13 12:01:02 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-08-13 12:01:02 +0200
commit9fcda6eda1644ce9e1ed12c4434bd29812923aca (patch)
tree81955a05de417ddeb599b96b7151141ab39ea370
parent7ae15b6c1929af96c04cb617fa02ec0ea7e63a76 (diff)
downloadscripts-9fcda6eda1644ce9e1ed12c4434bd29812923aca.tar.gz
htmlformat: dead-simply HTML formatter
Simple alternative to tidy Created at: 2013-08-28 00:03:00
-rwxr-xr-xhtmlformat18
1 files changed, 18 insertions, 0 deletions
diff --git a/htmlformat b/htmlformat
new file mode 100755
index 0000000..3c05e08
--- /dev/null
+++ b/htmlformat
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Simple XML formatter
+cat "$@" |
+tr -d '\n\r' |\
+sed 's|>[ \t]*|>|g' |\
+sed 's|<|\n<|g' |\
+awk -v step=' ' \
+'
+/^<\// {
+ s = substr(s, 1, length(s) - length(step));
+}
+{
+ print s $0;
+}
+/^<[^\/?]/{
+ if ($0 !~ /\/>/) s = s step;
+}
+'