Packets: Add packet diagrams
[senf.git] / doclib / filter.pl
index 0fd65d3..14ad930 100755 (executable)
@@ -1,8 +1,21 @@
 #!/usr/bin/perl -n
 
-if (/^\s*\\code\s*$/ .. /\\endcode/) {
-    $i=length((/^(\s*)/)[0]) if /^\s*\\code\s*$/;
-    print substr($_,$i);
-} else {
-    print;
+BEGIN {
+    ($topdir=$0) =~ s{doclib/.*$}{};
+    print $topdir,"\n";
+}
+
+s/\s*$//;
+while (s/\t/' 'x(8-length($`)%8)/e) {}
+
+if (/^\s*\\code$/ .. /\\endcode/ && !/^$/) {
+    $i=length($1) if /^(\s*)\\code$/;
+    print substr($_,$i),"\n";
+} 
+elsif (s/^(\s*)<pre>$/$1<pre class="fragment">/ .. /<\/pre>/ && !/^$/) {
+    $i=length($1) if /^(\s*)<pre class="fragment">$/;
+    print substr($_,$i),"\n";
+} 
+else {
+    print $_,"\n";
 }