<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# .txt as a wiki page type - links WikiLinks and URIs.
#
# Copyright (C) 2008 Gabriel McManus &lt;gmcmanus@gmail.com&gt;
# Licensed under the GNU General Public License, version 2 or later

package IkiWiki::Plugin::txt;

use warnings;
use strict;
use IkiWiki 2.00;
use HTML::Entities;

my $findurl=0;

sub import {
	hook(type =&gt; "getsetup", id =&gt; "txt", call =&gt; \&amp;getsetup);
	hook(type =&gt; "filter", id =&gt; "txt", call =&gt; \&amp;filter);
	hook(type =&gt; "htmlize", id =&gt; "txt", call =&gt; \&amp;htmlize);

	eval q{use URI::Find};
	if (! $@) {
		$findurl=1;
	}
}

sub getsetup () { #{{{
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 1, # format plugin
		},
} #}}}

# We use filter to convert raw text to HTML
# (htmlize is called after other plugins insert HTML)
sub filter (@) {
	my %params = @_;
	my $content = $params{content};

	if (defined $pagesources{$params{page}} &amp;&amp; $pagesources{$params{page}} =~ /\.txt$/) {
		encode_entities($content);
		if ($findurl) {
			my $finder = URI::Find-&gt;new(sub {
				my ($uri, $orig_uri) = @_;
				return qq|&lt;a href="$uri"&gt;$orig_uri&lt;/a&gt;|;
			});
			$finder-&gt;find(\$content);
		}
		$content = "&lt;pre&gt;" . $content . "&lt;/pre&gt;";
	}

	return $content;
}

# We need this to register the .txt file extension
sub htmlize (@) {
	my %params=@_;
	return $params{content};
}

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