Last active
August 29, 2015 14:00
-
-
Save ShimmerFairy/4fc6654c1fe0b43c0796 to your computer and use it in GitHub Desktop.
Simple link parser, for fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my token wikilink { | |
"[[" ~ "]]" [ | |
<( | |
[ <!before "]]"> . ]+ | |
)> | |
] | |
}; | |
sub percent-char($str) { | |
[~] $str.encode('utf-8').list.map: {"%" ~ $_.fmt("%02X")}; | |
} | |
say "[[abcde]] and [[f ghi j]] are on the [[APPLE ][]]" ~~ /<wikilink> +% .+?/; | |
say "Unencoded:"; | |
for @<wikilink> -> $NAME { | |
say "http://tcrf.net/" ~ $NAME.subst(/\s+/, '_', :g); | |
} | |
say "Encoded:"; | |
for @<wikilink> -> $NAME { | |
my $page = $NAME.subst(/\s+/, '_', :g); | |
$page.=subst(/<-[A..Za..z0..9\-_.~]>/, {percent-char(~$_)}, :g); | |
say "http://tcrf.net/$page"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl6 wltest.p6 | |
「[[abcde]] and [[f ghi j]] are on the [[APPLE ][]]」 | |
wikilink => 「abcde」 | |
wikilink => 「f ghi j」 | |
wikilink => 「APPLE ][」 | |
Unencoded: | |
http://tcrf.net/abcde | |
http://tcrf.net/f_ghi_j | |
http://tcrf.net/APPLE_][ | |
Encoded: | |
http://tcrf.net/abcde | |
http://tcrf.net/f_ghi_j | |
http://tcrf.net/APPLE_%5D%5B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment