<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
package IkiWiki::Plugin::wmd;

use warnings;
use strict;
use IkiWiki 3.00;
use Encode;

sub import {
	add_underlay("wmd");
	hook(type =&gt; "getsetup", id =&gt; "wmd", call =&gt; \&amp;getsetup);
	hook(type =&gt; "formbuilder_setup", id =&gt; "wmd", call =&gt; \&amp;formbuilder_setup);
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 0,
			section =&gt; "web",
		},
}

sub formbuilder_setup (@) {
	my %params=@_;
	my $form=$params{form};

	return if ! defined $form-&gt;field("do");
	
	return unless $form-&gt;field("do") eq "edit" ||
			$form-&gt;field("do") eq "create" ||
			$form-&gt;field("do") eq "comment";

	$form-&gt;tmpl_param("wmd_preview", "&lt;div class=\"wmd-preview\"&gt;&lt;/div&gt;\n".
		include_javascript(undef, 1));
}

sub include_javascript ($;$) {
	my $page=shift;
	my $absolute=shift;

	my $wmdjs=urlto("wmd/wmd.js", $page, $absolute);
	return &lt;&lt;"EOF"
&lt;script type="text/javascript"&gt;
wmd_options = {
	output: "Markdown"
};
&lt;/script&gt;
&lt;script src="$wmdjs" type="text/javascript"&gt;&lt;/script&gt;
EOF
}

1
</pre></body></html>