It bears writing in block caps...
#! /usr/bin/perl -w
$VSN = q$Id: outline2html,v 1.6 2002/06/19 01:50:29 mca1001 Exp $;
$VSN =~ s/.+?,v\s*(.+:\S+).*/$1/;
use strict;
use vars qw(@lvls $VSN);
use HTML::Entities;
use Tree::DAG_Node;
# these are local names & likely to change
use DAGnode_Import;
# use DAGnode_Export;
die "$0: stdin or one file --> stdout filter" if @ARGV > 1;
my $tree = Tree::DAG_Node::Import::outline2tree(\*ARGV, $ARGV[0]);
my @output;
$tree->walk_down
({ _depth => 0,
html => \@output,
showprivate => undef,
callback => sub {
my ($node, $opt) = @_;
# the file itself has no heading but the text at the top
# return 1 if $node->attributes->{'invented'};
my ($t, $h) = ($node->name, $opt->{'html'});
HTML::Entities::encode($t);
my $hidden = not ispublic($node, $opt->{'showprivate'});
$t = '<small>[Hidden tree section]</small>' if $hidden;
if ($opt->{'_depth'} == 0) {
push @$h, make_header($node, $t, $opt->{'showprivate'});
} else {
push @$h, join "", '<li><a name="', $node->address, '">', $t, "</a>";
}
return 0 if $hidden;
if ($node->attributes->{'text'} && $node->attributes->{'text'} =~ /\S/) {
$t = $node->attributes->{'text'};
chomp $t;
HTML::Entities::encode($t);
$t =~ s!((?:ht|f)tp://[-\w.]+(?:/\S*|))!<a href="$1">$1</a>!gi;
push @$h, "<pre>$t</pre>";
}
push @$h, "<ul>" if $node->daughters;
return 1;
},
callbackback => sub {
my ($node, $opt) = @_;
my $h = $opt->{'html'};
push @$h, "</ul>" if $node->daughters && ispublic($node, $opt->{'showprivate'});
push @$h, "</body>", "</html>" if $opt->{'_depth'} == 0;
},
});
print join "\n", @output;
sub ispublic ($$) {
my ($n, $t) = @_;
if ($n->name =~ /\[private(?::(\w+))?\]/i) {
return 0 unless defined $t && $1 eq $t;
} else {
return 1; # should probably track back up the tree from this point, to find ambiguous labelling
}
}
sub make_header # arg = (top-node, text-for-node, opt-showprivate)
{
my ($node, $t, $showpriv) = @_;
my @out;
my $now = scalar localtime();
push @out, split /\n/, <<HDR;
<html>
<head>
<meta name="generator" content="outline2html $VSN">
<title>$t</title>
</head><body>
<center><h1>outline2html: $t</h1></center>
<small><i>Generator version $VSN, run at $now</i></small>
<!--
THIS FILE WAS AUTOMATICALLY GENERATED.
EDITS TO IT MAY BE OVERWRITTEN.
-->
<table border="1" cellpadding="2" cellspacing="0">
HDR
# whip up an index of the top two rows
foreach my $k ($node->daughters) {
next unless ispublic($k, $showpriv);
my @row;
foreach my $gk ($k->daughters) {
next unless ispublic($gk, $showpriv);
push @row, '<small><a href="#'.$gk->address.'">'.$gk->name.'</a></small>';
}
push @out, '<tr><td><a href="#'.$k->address.'">'.$k->name.'</a></td>';
push @out, ' <td>'.(join ", ", @row).'</td></tr>';
}
push @out, '</table>';
return @out;
}
__DATA__
-*- blibbly wobble -*-
intro para
is here
* heading one
** headine 11 [private]
has some text
*** heading 111 [public]
but public inside private doesn't show, at least for now.
* heading two
** heading two>1
whoosh
*** heading two>1.a
** heading two>2
* heading three
|
Repository owner Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |