blob: 0f3fb0cc6e1c4a53f207ee554fbe66e554145887 (
plain)
- #!/usr/bin/perl
- use warnings;
- use strict;
- use Pandoc::Filter;
- use Pandoc::Elements;
- use URI;
- use URI::Escape;
- 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(uri_unescape(shift))->canonical->as_string;
- }
- sub pp_iri {
- return URI->new(uri_unescape(shift))->canonical->as_iri;
- }
- sub pp_string {
- my $string = shift;
- my $finder = URI::Find->new( \&pp_iri );
- $finder->find(\$string);
- return $string;
- }
|