summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2011-10-14 03:23:09 +0200
committerJonas Smedegaard <dr@jones.dk>2021-03-23 22:48:15 +0100
commit26ee0e72aa277cd3fe79cdeb0a0dab88d883dd92 (patch)
tree06de82280ab1bf36fdfff8aa6fcb1b492009f94b
parent5654b97d5dd88ecac0cba5f34cf7d57cbf052de0 (diff)
add plugin htmlpacker, to squash superfluous space in Markdown content
-rw-r--r--IkiWiki/Plugin/htmlpacker.pm40
1 files changed, 40 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/htmlpacker.pm b/IkiWiki/Plugin/htmlpacker.pm
new file mode 100644
index 0000000..cc1bf9c
--- /dev/null
+++ b/IkiWiki/Plugin/htmlpacker.pm
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::htmlpacker;
+
+# htmlpacker: HTML code cleaner
+#
+# Copyright 2011 Jonas Smedegaard <dr@jones.dk>
+# Based on htmlbalance which is...
+# Copyright 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/>
+# Licensed under the GNU GPL, version 2, or any later version published by the
+# Free Software Foundation
+
+use warnings;
+use strict;
+use IkiWiki 3.00;
+
+sub import {
+ hook(type => "getsetup", id => "htmlpacker", call => \&getsetup);
+ hook(type => "sanitize", id => "htmlpacker", call => \&sanitize);
+}
+
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => undef,
+ },
+}
+
+sub sanitize (@) {
+ my %params=@_;
+ my $ret = '';
+
+ eval q{use HTML::Packer};
+ error $@ if $@;
+ my $packer = HTML::Packer->init();
+ $ret = $packer->minify( \$params{content}, { html5 => $config{html5} } );
+ return $ret;
+}
+
+1