* Support htmlize plugins and make mdwn one such plugin, which is enabled by

default (of course!). Based on a patch by Faidon Liambotis.
master
joey 2006-07-03 22:08:04 +00:00
parent 7ea8df24b3
commit 6551c1e560
13 changed files with 78 additions and 39 deletions

View 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;
} #}}}

View File

@ -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

View 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");

View 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).

4
debian/changelog vendored
View 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

View 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]]

View 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]].

View 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]].

View File

@ -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.

View 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);

View 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.

View File

@ -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;

View File

@ -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");