summaryrefslogtreecommitdiff
path: root/mediawiki-uri-escape
diff options
context:
space:
mode:
Diffstat (limited to 'mediawiki-uri-escape')
-rwxr-xr-xmediawiki-uri-escape24
1 files changed, 24 insertions, 0 deletions
diff --git a/mediawiki-uri-escape b/mediawiki-uri-escape
new file mode 100755
index 0000000..40dd10c
--- /dev/null
+++ b/mediawiki-uri-escape
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+# work around modest URL parsing <https://github.com/jgm/pandoc/issues/1838>
+
+use warnings;
+use strict;
+
+use Path::Tiny;
+use Regexp::Common qw(net);
+use URI::Escape;
+
+my $infile = shift;
+my $outfile = shift || $infile;
+
+$_ = path($infile)->slurp_utf8;
+
+my $uri_path = qr!https?://$RE{net}{domain}{-nospace}(?::\d+)?\K(/\S*?)!;
+my $uri_end = qr!(?=[.,;]?[\s<\"\|}])!;
+
+s|\b$uri_path$uri_end|uri_escape(uri_unescape($1), "^A-Za-z0-9/\.")|eg;
+
+path($outfile)->spew_utf8($_);
+
+1;