2009-03-04 16:19:09 +01:00
|
|
|
The [StackOverflow](http://stackoverflow.com/) site uses markdown for markup.
|
|
|
|
It has a fancy javascript thing for showing a real-time preview of what the user
|
|
|
|
is editing. It would be nice if ikiwiki could support this, too. The thing they
|
|
|
|
use on StackOverflow is supposed to be free software, so it should be easy to
|
|
|
|
add to ikiwiki.
|
|
|
|
|
2009-03-04 19:53:34 +01:00
|
|
|
> See [[wikiwyg]]. Note that I do not have a copy of the code for that, or
|
|
|
|
> it'd be in ikiwiki already. --[[Joey]]
|
|
|
|
|
2009-03-04 23:30:11 +01:00
|
|
|
>> I just had a brief look at the [[wikiwyg]] page and the link to the plugin was
|
|
|
|
>> broken. The StackOverflow site uses the [WMD](http://wmd-editor.com/) editor,
|
|
|
|
>> which seems to be related to the [ShowDown](http://attacklab.net/showdown/)
|
|
|
|
>> javascript port of Markdown. Interestingly, [WMD source](http://wmd.googlecode.com/)
|
|
|
|
>> is now available under an MIT license, though it is supposedly undergoing heavy
|
|
|
|
>> refactoring. It looks like there was previous discussion ( [[todo/Add_showdown_GUI_input__47__edit]] )
|
|
|
|
>> about a showdown plugin. Maybe a WMD plugin would be worthwhile. I might
|
|
|
|
>> look into it if I have time on the weekend. -- [[Will]]
|
|
|
|
|
2009-03-06 09:40:50 +01:00
|
|
|
[[!tag wishlist]]
|
|
|
|
|
|
|
|
>>> Below is a simple plugin/[[patch]] to make use of the WMD editor. Turns out it isn't hard at all to
|
|
|
|
>>> get a basic version going (that don't handle directives at all). I've
|
|
|
|
>>> removed the done tag so this is visible as a patch. -- [[Will]]
|
|
|
|
|
|
|
|
------
|
|
|
|
|
|
|
|
### Instructions:
|
|
|
|
|
|
|
|
|
|
|
|
Download the [WMD source](http://wmd-editor.com/downloads/wmd-1.0.1.zip). In that zip file you'll
|
|
|
|
find a few example html files, a readme and `wmd` directory. Move the `wmd` directory into the
|
|
|
|
ikiwiki `underlays` directory. You should now have an `underlays/wmd/wmd.js` file as well as
|
|
|
|
some other javascript files and an images directory in the same place.
|
|
|
|
|
|
|
|
Note that the WMD plugin does **not** handle directives. For this reason the normal `preview` button
|
|
|
|
remains. Some CSS to clean up the display of the live WMD preview would be good.
|
|
|
|
|
|
|
|
Install the following patch and plugin file. Then enable the 'wmd' plugin.
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/templates/editpage.tmpl b/templates/editpage.tmpl
|
|
|
|
index 4b54db2..b1cf015 100644
|
|
|
|
--- a/templates/editpage.tmpl
|
|
|
|
+++ b/templates/editpage.tmpl
|
|
|
|
@@ -37,6 +37,7 @@ Optional comment about this change:<br />
|
|
|
|
</div>
|
|
|
|
</TMPL_IF>
|
|
|
|
<TMPL_VAR FORM-END>
|
|
|
|
+<TMPL_VAR WMD_PREVIEW>
|
|
|
|
|
|
|
|
<TMPL_IF NAME="PAGE_PREVIEW">
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::wmd;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki 3.00;
|
|
|
|
use POSIX;
|
|
|
|
use Encode;
|
|
|
|
|
|
|
|
sub import {
|
|
|
|
add_underlay("wmd");
|
|
|
|
hook(type => "getsetup", id => "wmd", call => \&getsetup);
|
|
|
|
hook(type => "formbuilder_setup", id => "wmd", call => \&formbuilder_setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getsetup () {
|
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
sub formbuilder_setup (@) {
|
|
|
|
my %params=@_;
|
|
|
|
my $form=$params{form};
|
|
|
|
|
|
|
|
return if ! defined $form->field("do");
|
|
|
|
|
|
|
|
return unless (($form->field("do") eq "edit") ||
|
|
|
|
($form->field("do") eq "create"));
|
|
|
|
|
|
|
|
$form->tmpl_param("wmd_preview", "<div class=\"wmd-preview\"></div>\n".include_javascript(undef, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub include_javascript ($;$) {
|
|
|
|
my $page=shift;
|
|
|
|
my $absolute=shift;
|
|
|
|
|
|
|
|
return '<script src="'.urlto("wmd.js", $page, $absolute).
|
|
|
|
'" type="text/javascript"></script>'."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
1
|
|
|
|
|