From 6ffe2a9773e56a77bd1f3a07301154f0eeb10db3 Mon Sep 17 00:00:00 2001 From: Niko Tyni Date: Sun, 6 Mar 2005 17:41:33 +0000 Subject: * trunk/website/bin/nestfix.pl: + renamed to branches/2.0/util/fix-pod2html.pl * branches/2.0/Makefile: + fix pod2html output with util/fix-pod2html.pl * branches/2.0/util/fix-pod2html.pl: + v1.4: insert the "N" letter into too. * trunk/website/bin/pod2wml.sh: + use fix-pod2html.pl from branches/2.0 --- util/fix-pod2html.pl | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 util/fix-pod2html.pl (limited to 'util') 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 and tags until +# the next
,
or + +# v1.1: don't nest any elements; +# end one before beginning another + +# v1.2: insert
tags if
occurs +# inside
+ +# v1.3: anchors must not start with a digit; +# insert a letter "N" at the start if they do + +# v1.4: insert the "N" letter into 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 "
"; + } + unshift @stack, 0; + } + if (($tag eq "dt" or $tag eq "dd") and $stack[0]) { + print ""; + $stack[0] = 0; + } + if ($tag eq "a") { + if ($a) { + print ""; + } else { + $a++; + } + $text =~ s/(name="|href="#)(\d)/$1N$2/; + } + print $text; +} + + +sub endsub { + my $tag = shift; + my $text = shift; + if ($tag eq "dl") { + print "" if $stack[0]; + shift @stack; + } + if ($tag eq "a") { + if ($a) { + print ""; + $a--; + } + } elsif ($tag eq "dd" or $tag eq "dt") { + $stack[0] = $tag; + } else { + print $text; + } +} -- cgit v1.2.3-24-g4f1b