]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Support htmlize plugins and make mdwn one such plugin, which is enabled by
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Mon, 3 Jul 2006 22:08:04 +0000 (22:08 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Mon, 3 Jul 2006 22:08:04 +0000 (22:08 +0000)
  default (of course!). Based on a patch by Faidon Liambotis.

13 files changed:
IkiWiki.pm
IkiWiki/Plugin/mdwn.pm [new file with mode: 0644]
IkiWiki/Render.pm
basewiki/markdown.mdwn
debian/changelog
doc/features.mdwn
doc/index.mdwn
doc/plugins.mdwn
doc/plugins/mdwn.mdwn [new file with mode: 0644]
doc/plugins/write.mdwn
doc/usage.mdwn
t/crazy-badass-perl-bug.t
t/htmlize.t

index 7be1c7f589c0f9cccddc1a05e209a2f55da1f6a2..39ceec04e449c3a9863c1fa1a0a92f97791d8a38 100644 (file)
@@ -42,7 +42,7 @@ sub defaultconfig () { #{{{
        setup => undef,
        adminuser => undef,
        adminemail => undef,
-       plugin => [qw{inline htmlscrubber}],
+       plugin => [qw{mdwn inline htmlscrubber}],
        timeformat => '%c',
 } #}}}
            
@@ -123,12 +123,10 @@ sub dirname ($) { #{{{
 sub pagetype ($) { #{{{
        my $page=shift;
        
-       if ($page =~ /\.mdwn$/) {
-               return ".mdwn";
-       }
-       else {
-               return "unknown";
+       if ($page =~ /\.(.*)$/) {
+               return $1 if exists $hooks{htmlize}{$1};
        }
+       return "unknown";
 } #}}}
 
 sub pagename ($) { #{{{
@@ -136,7 +134,7 @@ sub pagename ($) { #{{{
 
        my $type=pagetype($file);
        my $page=$file;
-       $page=~s/\Q$type\E*$// unless $type eq 'unknown';
+       $page=~s/\Q.$type\E*$// unless $type eq 'unknown';
        return $page;
 } #}}}
 
diff --git a/IkiWiki/Plugin/mdwn.pm b/IkiWiki/Plugin/mdwn.pm
new file mode 100644 (file)
index 0000000..a344de0
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+# Markdown markup language
+package IkiWiki::Plugin::mdwn;
+
+use warnings;
+use strict;
+use IkiWiki;
+
+sub import { #{{{
+       IkiWiki::hook(type => "htmlize", id => "mdwn", call => \&htmlize);
+} # }}}
+
+sub htmlize ($) { #{{{
+       my $content = shift;
+
+       if (! $INC{"/usr/bin/markdown"}) {
+               # Note: a proper perl module is available in Debian
+               # for markdown, but not upstream yet.
+               no warnings 'once';
+               $blosxom::version="is a proper perl module too much to ask?";
+               use warnings 'all';
+               do "/usr/bin/markdown";
+               require Encode;
+       }
+       
+       # Workaround for perl bug (#376329)
+       $content=Encode::encode_utf8($content);
+       $content=Encode::encode_utf8($content);
+       $content=Markdown::Markdown($content);
+       $content=Encode::decode_utf8($content);
+       $content=Encode::decode_utf8($content);
+
+       return $content;
+} # }}}
+
+1
index ac8f0393743a4c1889d55a9557896a2baa8b7d74..8a4fb89eb955f113d1d15059f52ea0390738be71 100644 (file)
@@ -25,22 +25,8 @@ sub htmlize ($$) { #{{{
        my $type=shift;
        my $content=shift;
        
-       if (! $INC{"/usr/bin/markdown"}) {
-               # Note: a proper perl module is available in Debian
-               # for markdown, but not upstream yet.
-               no warnings 'once';
-               $blosxom::version="is a proper perl module too much to ask?";
-               use warnings 'all';
-               do "/usr/bin/markdown";
-       }
-       
-       if ($type eq '.mdwn') {
-               # Workaround for perl bug (#376329)
-               $content=Encode::encode_utf8($content);
-               $content=Encode::encode_utf8($content);
-               $content=Markdown::Markdown($content);
-               $content=Encode::decode_utf8($content);
-               $content=Encode::decode_utf8($content);
+       if (exists $hooks{htmlize}{$type}) {
+               $content=$hooks{htmlize}{$type}{call}->($content);
        }
        else {
                error("htmlization of $type not supported");
index 57fb259f82d8d76db942aa0a560615e832441f41..317a17db9aced10b5db3a5ffea684953a6e6b8bb 100644 (file)
@@ -1,6 +1,6 @@
 [Markdown](http://daringfireball.net/projects/markdown/)
 is a minimal markup language that resembles plain text as used in
-email messages. It is the markup language used by this wiki.
+email messages. It is the markup language used by this wiki by default.
 
 For documentation about the markdown syntax, see [[HelpOnFormatting]] and
 [Markdown: syntax](http://daringfireball.net/projects/markdown/syntax).
index 082ab418f76a3b44ec78115f4b104a9bf7f122d4..1fafe41681967e837b8925940849a7a4dc1bd6e6 100644 (file)
@@ -27,8 +27,10 @@ ikiwiki (1.8) UNRELEASED; urgency=low
     This allows adding or removing plugins w/o overriding the whole list of
     default plugins, which makes it easier to upgrade when new default plugins
     are added.
+  * Support htmlize plugins and make mdwn one such plugin, which is enabled by
+    default (of course!). Based on a patch by Faidon Liambotis.
 
- -- Joey Hess <joeyh@debian.org>  Mon,  3 Jul 2006 16:57:37 -0400
+ -- Joey Hess <joeyh@debian.org>  Mon,  3 Jul 2006 18:06:49 -0400
 
 ikiwiki (1.7) unstable; urgency=low
 
index f116e00e3cdf79ef9dd77627b4720c69a687d4eb..0992130e5b28d2ce88112f0774479e10412cca87 100644 (file)
@@ -26,6 +26,9 @@ Some of ikiwiki's features:
   provided by ikiwiki aside from regular markdown is the [[WikiLink]] and 
   [[PreprocessorDirective]]
 
+  If you prefer to use some other markup language, ikiwiki allows others to
+  be added by [[plugins]].
+
 * support for other file types
 
   ikiwiki also supports files of any other type, including plain text,
@@ -120,10 +123,10 @@ Some of ikiwiki's features:
 * [[Plugins]]
 
   Plugins can be used to add additional features to ikiwiki. The interface
-  is quite flexible, allowing plugins to register
-  [[PreProcessorDirective]]s, hook into [[CGI]] mode, and more. Ikiwiki's
-  backend RCS support is also pluggable, so support for new revision
-  control systems can be added to ikiwiki. 
+  is quite flexible, allowing plugins to implement additional markup
+  languages, register [[PreProcessorDirective]]s, hook into [[CGI]] mode,
+  and more. Ikiwiki's backend RCS support is also pluggable, so support for
+  new revision control systems can be added to ikiwiki. 
 
 * [[todo/utf8]]
 
index c247cf7441e78c6546ff438acd0fa5d0c15ade7c..3191d1c24889893456280dfb307a7993cbacf3b1 100644 (file)
@@ -1,8 +1,8 @@
 [[ikiwiki_logo|logo/ikiwiki.png]]  
 ikiwiki is a **wiki compiler**. It converts wiki pages
 into html pages suitable for publishing on a website. Unlike a traditional
-wiki, ikiwiki does not have its own means of storing page history or its own
-markup language. Instead it can use [[Subversion]] (or [[Git]]) and [[MarkDown]].
+wiki, ikiwiki does not have its own means of storing page history.
+Instead it can use [[Subversion]] (or [[Git]]).
 
 * [[News]] is a blog (built using ikiwiki) of news items about ikiwiki. It's the best way to find out when there's a new version to [[Download]].
 
index 05b661f2b916834508713654eb0d86a86668401f..d79a3bd3b4dce60f0f330c0c28bff6f8efc0a4a7 100644 (file)
@@ -1,7 +1,7 @@
 There's documentation if you want to [[write]] your own plugins, or you can
 install and use plugins contributed by others. 
 
-The [[inline]] and [[htmlscrubber]] plugins are enabled by default.
+The [[mdwn]], [[inline]], and [[htmlscrubber]] plugins are enabled by default.
 
 To enable other plugins, use the `--plugin` switch described in [[usage]],
 or the equivalent `add_plugins` line in [[ikiwiki.setup]].
diff --git a/doc/plugins/mdwn.mdwn b/doc/plugins/mdwn.mdwn
new file mode 100644 (file)
index 0000000..d1b1254
--- /dev/null
@@ -0,0 +1,3 @@
+This plugin, which is enabled by default, lets ikwiki convert files with
+names ending in ".mwdn" to html. It uses the [[markdown]] minimal markup
+language.
index 515c4d90d6091766a90b01a498507bd47bf99f4a..5be90efdfb73be9a286ce234e0aad5e3fba367a2 100644 (file)
@@ -55,7 +55,8 @@ Note that if the [[htmlscrubber]] is enabled, html in
 [[PreProcessorDirective]] output is sanitised, which may limit what your
 plugin can do. Also, the rest of the page content is not in html format at
 preprocessor time. Text output by a preprocessor directive will be passed
-through markdown along with the rest of the page.
+through markdown (or whatever engine is used to htmlize the page) along
+with the rest of the page.
 
 # Other types of hooks
 
@@ -79,6 +80,15 @@ Runs on the raw source of a page, before anything else touches it, and can
 make arbitrary changes. The function is passed named parameters `page` and
 `content` and should return the filtered content.
 
+## htmlize
+
+       IkiWiki::hook(type => "htmlize", id => "ext", call => \&filter);
+
+Runs on the raw source of a page and turns it into html. The id parameter
+specifies the filename extension that a file must have to be htmlized using
+this plugin. This is how you can add support for new and exciting markup
+languages to ikiwiki.
+
 ## pagetemplate
 
        IkiWiki::hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
index deb94e415c4214f09c6ceadbf3b1d4c1730f3cdb..6ff71056f2bd018b411f246c25b590a5fd86d849 100644 (file)
@@ -11,7 +11,8 @@ ikiwiki --setup configfile
 # DESCRIPTION
 
 `ikiwiki` is a wiki compiler. It builds static html pages for a wiki, from
-`source` in the [[MarkDown]] language, and writes it out to `destination`.
+`source` in the [[MarkDown]] language (or others), and writes it out to
+`destination`.
 
 Note that most options can be shortened to single letters, and boolean
 flags such as --verbose can be negated with --no-verbose.
index 69e9731d833c8808c5d4b134c8ad8635a97620e1..f54f27c4bcaec16cbd341a12cc8abea877a32005 100755 (executable)
@@ -14,6 +14,6 @@ BEGIN { use_ok("IkiWiki::Render"); }
 %IkiWiki::config=IkiWiki::defaultconfig();
 $IkiWiki::config{srcdir}=$IkiWiki::config{destdir}="/dev/null";
 IkiWiki::checkconfig();
-ok(IkiWiki::htmlize(".mdwn", IkiWiki::readfile("t/test1.mdwn")));
-ok(IkiWiki::htmlize(".mdwn", IkiWiki::readfile("t/test3.mdwn")),
+ok(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test1.mdwn")));
+ok(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test3.mdwn")),
        "wtf?") for 1..100;
index 742b6e2bcaa6336f829c00409e1d2b7f89cbd395..687eb03a8b104a67b848e12c9ccc57beb81e9643 100755 (executable)
@@ -12,10 +12,10 @@ BEGIN { use_ok("IkiWiki::Render"); }
 $IkiWiki::config{srcdir}=$IkiWiki::config{destdir}="/dev/null";
 IkiWiki::checkconfig();
 
-is(IkiWiki::htmlize(".mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
+is(IkiWiki::htmlize("mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
        "basic");
-is(IkiWiki::htmlize(".mdwn", IkiWiki::readfile("t/test1.mdwn")),
+is(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test1.mdwn")),
        Encode::decode_utf8(qq{<p><img src="../images/o.jpg" alt="o" title="&oacute;" />\nóóóóó</p>\n}),
        "utf8; bug #373203");
-ok(IkiWiki::htmlize(".mdwn", IkiWiki::readfile("t/test2.mdwn")),
+ok(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test2.mdwn")),
        "this file crashes markdown if it's fed in as decoded utf-8");