changeset 16:f0884c3c035a

2007-08-14 17:58:18 by steve Support textile / markdown / html by default.
author steve
date Tue, 14 Aug 2007 17:58:18 +0000
parents b8a289afc783
children d8a5506ec11b
files Makefile bin/chronicle etc/chroniclerc
diffstat 3 files changed, 137 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Aug 14 17:47:09 2007 +0000
+++ b/Makefile	Tue Aug 14 17:58:18 2007 +0000
@@ -8,14 +8,14 @@
 # --
 # http://www.steve.org.uk/
 #
-# $Id: Makefile,v 1.3 2007-08-13 23:22:03 steve Exp $
+# $Id: Makefile,v 1.4 2007-08-14 17:58:18 steve Exp $
 
 
 #
 #  Only used to build distribution tarballs.
 #
 DIST_PREFIX = ${TMP}
-VERSION     = 0.1
+VERSION     = 0.2
 BASE        = chronicle
 
 
--- a/bin/chronicle	Tue Aug 14 17:47:09 2007 +0000
+++ b/bin/chronicle	Tue Aug 14 17:58:18 2007 +0000
@@ -54,7 +54,7 @@
  --
  http://www.steve.org.uk/
 
- $Id: chronicle,v 1.7 2007-08-14 14:22:05 steve Exp $
+ $Id: chronicle,v 1.8 2007-08-14 17:58:18 steve Exp $
 
 =cut
 
@@ -245,6 +245,7 @@
     $CONFIG{'output'}     = "./output";
     $CONFIG{'template'}   = "./themes/default";
     $CONFIG{'url-prefix'} = "";
+    $CONFIG{'format'}     = 'html';
 }
 
 
@@ -294,7 +295,7 @@
 
     if ( $VERSION )
     {
-        my $REVISION      = '$Revision: 1.7 $';
+        my $REVISION      = '$Revision: 1.8 $';
         if ( $REVISION =~ /1.([0-9.]+) / )
         {
             $REVISION = $1;
@@ -1094,6 +1095,27 @@
     close( ENTRY );
 
     #
+    #  Convert the body if we're supposed to.
+    #
+    if ( $CONFIG{'format'} eq 'html' )
+    {
+        # nop
+    }
+    elsif( lc($CONFIG{'format'}) eq 'markdown' )
+    {
+        $body = markdown2HTML( $body );
+    }
+    elsif( lc($CONFIG{'format'}) eq 'textile' )
+    {
+        $body = textile2HTML( $body );
+    }
+    else
+    {
+        print "Unkown blog entry format.  Leaving text as raw\n";
+    }
+
+    #
+    #
     #  If we have title then we can store it
     #
     my $entryTags;
@@ -1336,3 +1358,93 @@
         }
     }
 }
+
+
+
+=begin doc
+
+  Convert from markdown to HTML.
+
+=end doc
+
+=cut
+
+sub markdown2HTML
+{
+    my( $text ) = (@_);
+
+    #
+    #  Make sure we have the module installed.  Use eval to
+    # avoid making this mandatory.
+    #
+    my $test    = "use Text::Markdown;";
+
+    #
+    #  Test loading the module.
+    #
+    eval( $test );
+    if ( $@ )
+    {
+        print <<EOF;
+
+  You have chosen to format your input text via Markdown, but the
+ Perl module Text::Markdown is not installed.
+
+  Aborting.
+EOF
+        exit;
+    }
+
+    #
+    #  Convert.
+    #
+    $text = Text::Markdown::Markdown( $text );
+    return( $text );
+}
+
+
+
+=begin doc
+
+  Convert from textile to HTML.
+
+=end doc
+
+=cut
+
+sub textile2HTML
+{
+    my( $text ) = (@_);
+
+    #
+    #  Make sure we have the module installed.  Use eval to
+    # avoid making this mandatory.
+    #
+    my $test    = "use Text::Textile;";
+
+    #
+    #  Test loading the module.
+    #
+    eval( $test );
+    if ( $@ )
+    {
+        print <<EOF;
+
+  You have chosen to format your input text via Textile, but the
+ Perl module Text::Textile is not installed.
+
+  Aborting.
+EOF
+        exit;
+    }
+
+    #
+    #  Convert.
+    #
+    $text = Text::Textile::textile( $text );
+    return( $text );
+}
+
+
+
+
--- a/etc/chroniclerc	Tue Aug 14 17:47:09 2007 +0000
+++ b/etc/chroniclerc	Tue Aug 14 17:58:18 2007 +0000
@@ -53,6 +53,27 @@
 
 
 #
+#  Here we specify the format the blog entries are written in.
+#
+#  Valid choices are:
+#
+#   html
+#   ----  
+#    The blog entries aren't touched and are inserted as-is.
+#
+#   markdown
+#   --------
+#    The blog entries are converted from markdown -> html then output.
+#
+#   textile
+#   -------
+#    The blog entries are converted from textile -> html then output.
+#
+# format = html
+#
+
+
+#
 #  We can disable the sidebar if we want
 #
 #  no-tags = 1