summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rwxr-xr-xutil/fix-pod2html.pl73
2 files changed, 74 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index de1ec81..8a4795a 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ HTML= $(addsuffix .html,$(BASE))
POD2MAN = pod2man --release=$(VERSION) --center=SmokePing $<
MAN2TXT = $(GROFF) -man -Tascii $< > $@
# pod2html apparently needs to be in the target directory to get L<> links right
-POD2HTML= cd $(dir $@); top="$(shell echo $(dir $@)|sed -e 's,doc/,,' -e 's,[^/]*/,../,g' -e 's,/$$,,')"; top=$${top:-.}; pod2html --infile=$(CURDIR)/$< --outfile=$(notdir $@) --noindex --htmlroot=. --podroot=. --podpath=$${top} --title=$*
+POD2HTML= cd $(dir $@); top="$(shell echo $(dir $@)|sed -e 's,doc/,,' -e 's,[^/]*/,../,g' -e 's,/$$,,')"; top=$${top:-.}; pod2html --infile=$(CURDIR)/$< --noindex --htmlroot=. --podroot=. --podpath=$${top} --title=$* | $${top}/../util/fix-pod2html.pl > $(notdir $@)
# we go to this trouble to ensure that MAKEPOD only uses modules in the installation directory
MAKEPOD= perl -Ilib -I/usr/pack/rrdtool-1.0.47-to/lib/perl -mSmokeping -e 'Smokeping::main()' -- --makepod
GENEX= perl -Ilib -I/usr/pack/rrdtool-1.0.47-to/lib/perl -mSmokeping -e 'Smokeping::main()' -- --gen-examples
diff --git a/util/fix-pod2html.pl b/util/fix-pod2html.pl
new file mode 100755
index 0000000..fa51400
--- /dev/null
+++ b/util/fix-pod2html.pl
@@ -0,0 +1,73 @@
+#!/usr/bin/perl -w
+
+use strict;
+use HTML::Parser;
+
+# fix pod2html output:
+# v1.0: defer </dd> and </dt> tags until
+# the next <dd>, <dt> or </dl>
+
+# v1.1: don't nest any <a> elements;
+# end one before beginning another
+
+# v1.2: insert <dd> tags if <dl> occurs
+# inside <dt>
+
+# v1.3: <a> anchors must not start with a digit;
+# insert a letter "N" at the start if they do
+
+# v1.4: insert the "N" letter into <a href="#xxx"> too.
+
+my $p = HTML::Parser->new(api_version => 3);
+$p->handler(start => \&startsub, 'tagname, text');
+$p->handler(end => \&endsub, 'tagname, text');
+$p->handler(default => sub { print shift() }, 'text');
+$p->parse_file(shift||"-") or die("parse: $!");
+
+my @stack;
+my $a=0;
+
+sub startsub {
+ my $tag = shift;
+ my $text = shift;
+ if ($tag eq "dl") {
+ if (@stack and $stack[0] eq "dt") {
+ $stack[0] = "dd";
+ print "</dt><dd>";
+ }
+ unshift @stack, 0;
+ }
+ if (($tag eq "dt" or $tag eq "dd") and $stack[0]) {
+ print "</$stack[0]>";
+ $stack[0] = 0;
+ }
+ if ($tag eq "a") {
+ if ($a) {
+ print "</a>";
+ } else {
+ $a++;
+ }
+ $text =~ s/(name="|href="#)(\d)/$1N$2/;
+ }
+ print $text;
+}
+
+
+sub endsub {
+ my $tag = shift;
+ my $text = shift;
+ if ($tag eq "dl") {
+ print "</$stack[0]>" if $stack[0];
+ shift @stack;
+ }
+ if ($tag eq "a") {
+ if ($a) {
+ print "</a>";
+ $a--;
+ }
+ } elsif ($tag eq "dd" or $tag eq "dt") {
+ $stack[0] = $tag;
+ } else {
+ print $text;
+ }
+}