sub story { my ($source, $doc_magic, $line_magic) = @_; my $inc = 0; my @sections; my @toc; while (my $line = <$source>) { chomp($line); next if !$line; if ($line =~ /^2/) { my ($number,$text) = split(/ /,$line,2); push @toc, anchor(textify($text), { href => '#'.idify($text) }); $inc++; } push @{$sections[$inc]}, $line; } my $tab = 3; $inc = 0; for my $section (@sections) { if ($section) { section($tab, sub { $tab++; for my $line (@{$section}) { my $line = convert_string($line, $line_magic); line($tab, $line), next if $line =~ /^"), next if $line =~ /^[bh]r$/; $doc_magic->{$1}->(), next if $line =~ /^&\s+(.*)/; blockquote($tab, $1), next if $line =~ /^bq\s(.*)/; item($tab + 1, $1), next if $line =~ /^\*\s(.*)/; item($tab + 1, $2, { value => $1 }), next if $line =~ /^\*(\d+)\s(.*)/; item($tab + 1, "$1 $2"), next if $line =~ /^\*s\s(.+\:)\s(.*)$/; row($tab + 1, $1, row_line($2)), next if $line =~ /^\|\s(.+)\s\|\|(.+)$/; heading($tab, $1, $2, { id => idify($2) }), next if $line =~ /^([1-6])\s+(.*)/; paragraph($tab, $line, { class => 'author' }), next if $line =~ /^by /; paragraph($tab, $line); } $tab--; }); } if ($inc == 0 && @toc > 3) { section($tab, sub { my $class = @toc > 25 ? @toc > 50 ? 'four' : 'three' : 'two'; my $style = @toc > 50 ? 'font-size:smaller' : undef; list($tab + 1, 'u', \@toc, { class => $class, style => $style }); }, { class => 'contents'} ); } $inc++; } # paragraph($tab,"written by $root_user", { class => 'author' }); }