<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::format;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
	hook(type =&gt; "preprocess", id =&gt; "format", call =&gt; \&amp;preprocess);
	hook(type =&gt; "getsetup",   id =&gt; "format", call =&gt; \&amp;getsetup);
}

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

sub preprocess (@) {
	my %params=@_;
	my $format=shift;
	shift;
	my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
	shift;

	if (! defined $format || ! defined $text) {
		error(gettext("must specify format and text"));
	}
		
	# Other plugins can register htmlizeformat hooks to add support
	# for page types not suitable for htmlize, or that need special
	# processing when included via format. Try them until one succeeds.
	my $ret;
	IkiWiki::run_hooks(htmlizeformat =&gt; sub {
		$ret=shift-&gt;($format, $text)
			unless defined $ret;
	});

	if (defined $ret) {
		return $ret;
	}
	elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
		return IkiWiki::htmlize($params{page}, $params{destpage},
		                        $format, $text);
	}
	else {
		error(sprintf(gettext("unsupported page format %s"), $format));
	}
}

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