Apache/OTL.pm
changeset 3 1b5eb968d2c4
parent 1 1ae1a79094fa
--- a/Apache/OTL.pm	Fri Jul 24 07:49:52 2009 -0700
+++ b/Apache/OTL.pm	Thu Oct 29 15:27:35 2009 -0700
@@ -1,7 +1,7 @@
 #
 # VimOutliner (OTL) XHTML pretty printer for mod_perl2/apache2.
 #
-# Copyright (c) 2006, Mahlon E. Smith <mahlon@martini.nu>
+# Copyright (c) 2006-2009, Mahlon E. Smith <mahlon@martini.nu>
 # All rights reserved.
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are met:
@@ -40,7 +40,7 @@
 
 sub handler
 {
-    my $VERSION = '0.5';
+    my $VERSION = '0.6';
     my $ID      = '$Id$';
     my $r       = shift;
     my $t0      = Time::HiRes::gettimeofday;
@@ -70,7 +70,10 @@
         percent     => qr/(\[.\]) (\d+)%/,
         todo        => qr/(\[_\]) /,
         done        => qr/(\[X\]) /,
-        comment     => qr/^(?:\t+)?:(.+)/,
+        user        => qr/^(?:\t+)?\<(.+)/,
+        user_wrap   => qr/^(?:\t+)?\>(.+)/,
+        body_wrap   => qr/^(?:\t+)?:(.+)/,
+        body        => qr/^(?:\t+)?;(.+)/,
         time        => qr/(\d{2}:\d{2}:\d{2})/,
         date        => qr/(\d{2,4}-\d{2}-\d{2})/,
         subitem     => qr/^\t(?!\t)/,
@@ -104,8 +107,8 @@
     # get optional settings and otl title
     {
         my $settings = shift @blocks;
-        if ($settings =~ $re{comment}) {
-            %opt = map { split /=/ } split /\s?:/, $settings;
+        if ($settings =~ $re{user}) {
+            %opt = map { split /=/ } split /\s?:/, $1;
         }
         
         # if the first group wasn't a comment,
@@ -116,6 +119,10 @@
         }
     }
 
+    # Now that we have tried to detect settings,
+    # remove any level 0 blocks that are user data.
+    @blocks = grep { $_ !~ /^[\<\>]/ } @blocks;
+
     # GET args override settings
     $opt{$_} = $get->{$_} foreach keys %$get;
 
@@ -133,7 +140,7 @@
     <!--
         generated by otl_handler $VERSION
         Mahlon E. Smith <mahlon\@martini.nu>
-        http://www.martini.nu/
+        http://projects.martini.nu/apache-otl/
 
         Get VimOutliner at: http://www.vimoutliner.org/
     -->
@@ -195,13 +202,18 @@
 
     foreach my $block ( sort { sorter(\%opt, \%re) } @blocks ) {
         # separate outline items
-        my @lines = grep { $_ !~ /$re{'hideline'}/ } split /\n/, $block;
+        my @lines;
+        foreach my $line ( split /\n/, $block ) {
+            push @lines, $line unless $line =~ $re{hideline} ||
+                $line =~ $re{user} || $line =~ $re{user_wrap};
+        }
+
         my $data  = [];
 
         # build structure and get item counts
         my ( $subs, $comments, $subsubs ) = ( 0, 0, 0 );
         foreach ( @lines ) {
-            if (/$re{comment}/) {
+            if (/$re{body_wrap}/) {
                 $comments++;
             }
             elsif (/$re{subitem}/) {
@@ -245,9 +257,10 @@
             }
 
             my $li_class = '>';
-            $li_class = ' class="todo">'    if $line =~ s#$re{todo}##;
-            $li_class = ' class="done">'    if $line =~ s#$re{done}##;
-            $li_class = ' class="comment">' if $line =~ s#$re{comment}#$1#;
+            $li_class = ' class="todo">'        if $line =~ s#$re{todo}##;
+            $li_class = ' class="done">'        if $line =~ s#$re{done}##;
+            $li_class = ' class="comment_pre">' if $line =~ s#$re{body}#$1#;
+            $li_class = ' class="comment">'     if $line =~ s#$re{body_wrap}#$1#;
 
             if ( $next_level == $level || $next_level == 0 ) {
                 $r->print( "$in<li" . $li_class . "$line</li>\n" );