diff options
author | Jonas Smedegaard <dr@jones.dk> | 2014-12-25 18:19:55 +0100 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2014-12-25 18:19:55 +0100 |
commit | 5cbb6b9dca11fe98b2feefcd31684ee2c2f1455a (patch) | |
tree | eef9ca15ab02bfc1873d3875350faa671188fea9 /pandoc-iri | |
parent | 7912a20b53c06e5eb8ef9682d06bd57429a87fca (diff) |
Rename and shorten filters.
Diffstat (limited to 'pandoc-iri')
-rwxr-xr-x | pandoc-iri | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/pandoc-iri b/pandoc-iri new file mode 100755 index 0000000..94be2e4 --- /dev/null +++ b/pandoc-iri @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use Pandoc::Filter; +use Pandoc::Elements; + +use URI; +use URI::Find; + +pandoc_filter( + \&link_normalize, +); + +sub link_normalize { + my $self = shift; + return [ Link( + $self->content, + [ pp_uri($self->target->[0]) => '' ] + )] + if ( $self->name eq 'Link' ); + return [ Str pp_string($self->content) ] + if ( $self->name eq 'Str' ); + return; +} + +sub pp_uri { + return URI->new(shift)->canonical->as_string; +} + +sub pp_iri { + return URI->new(shift)->canonical->as_iri; +} + +sub pp_string { + my $string = shift; + my $finder = URI::Find->new( \&pp_iri ); + $finder->find(\$string); + return $string; +} |