#! /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 = '[Hidden tree section]' if $hidden; if ($opt->{'_depth'} == 0) { push @$h, make_header($node, $t, $opt->{'showprivate'}); } else { push @$h, join "", '
  • ', $t, ""; } 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*|))!$1!gi; push @$h, "
    $t
    "; } push @$h, "" if $node->daughters && ispublic($node, $opt->{'showprivate'}); push @$h, "", "" 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/, < $t

    outline2html: $t

    Generator version $VSN, run at $now 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, ''.$gk->name.''; } push @out, ''; push @out, ' '; } push @out, '
    '.$k->name.''.(join ", ", @row).'
    '; 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