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

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "mdwn", call =&gt; \&amp;getsetup);
	hook(type =&gt; "htmlize", id =&gt; "mdwn", call =&gt; \&amp;htmlize, longname =&gt; "Markdown");
}

sub getsetup () {
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 1, # format plugin
			section =&gt; "format",
		},
		multimarkdown =&gt; {
			type =&gt; "boolean",
			example =&gt; 0,
			description =&gt; "enable multimarkdown features?",
			safe =&gt; 1,
			rebuild =&gt; 1,
		},
		nodiscount =&gt; {
			type =&gt; "boolean",
			example =&gt; 0,
			description =&gt; "disable use of markdown discount?",
			safe =&gt; 1,
			rebuild =&gt; 1,
		},
}

my $markdown_sub;
sub htmlize (@) {
	my %params=@_;
	my $content = $params{content};

	if (! defined $markdown_sub) {
		# Markdown is forked and splintered upstream and can be
		# available in a variety of forms. Support them all.
		no warnings 'once';
		$blosxom::version="is a proper perl module too much to ask?";
		use warnings 'all';

		if (exists $config{multimarkdown} &amp;&amp; $config{multimarkdown}) {
			eval q{use Text::MultiMarkdown};
			if ($@) {
				debug(gettext("multimarkdown is enabled, but Text::MultiMarkdown is not installed"));
			}
			else {
				$markdown_sub=sub {
					Text::MultiMarkdown::markdown(shift, {use_metadata =&gt; 0});
				}
			}
		}
		if (! defined $markdown_sub &amp;&amp;
		    (! exists $config{nodiscount} || ! $config{nodiscount})) {
			eval q{use Text::Markdown::Discount};
			if (! $@) {
				$markdown_sub=sub {
					my $t=shift;
					# Workaround for discount binding bug
					# https://rt.cpan.org/Ticket/Display.html?id=73657
					return "" if $t=~/^\s*$/;
					# Workaround for discount's eliding
					# of &lt;style&gt; blocks.
					# https://rt.cpan.org/Ticket/Display.html?id=74016
					$t=~s/&lt;style/&lt;elyts/ig;
					my $r=Text::Markdown::Discount::markdown($t);
					$r=~s/&lt;elyts/&lt;style/ig;
					return $r;
				}
			}
		}
		if (! defined $markdown_sub) {
			eval q{use Text::Markdown};
			if (! $@) {
				if (Text::Markdown-&gt;can('markdown')) {
					$markdown_sub=\&amp;Text::Markdown::markdown;
				}
				else {
					$markdown_sub=\&amp;Text::Markdown::Markdown;
				}
			}
			else {
				eval q{use Markdown};
				if (! $@) {
					$markdown_sub=\&amp;Markdown::Markdown;
				}
				else {
					my $error = $@;
					do "/usr/bin/markdown" ||
						error(sprintf(gettext("failed to load Markdown.pm perl module (%s) or /usr/bin/markdown (%s)"), $error, $!));
					$markdown_sub=\&amp;Markdown::Markdown;
				}
			}
		}
		
		require Encode;
	}
	
	# Workaround for perl bug (#376329)
	$content=Encode::encode_utf8($content);
	eval {$content=&amp;$markdown_sub($content)};
	if ($@) {
		eval {$content=&amp;$markdown_sub($content)};
		print STDERR $@ if $@;
	}
	$content=Encode::decode_utf8($content);

	return $content;
}

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