Skip to content

Instantly share code, notes, and snippets.

@gerdr
Last active December 10, 2015 16:38
Show Gist options
  • Save gerdr/4462564 to your computer and use it in GitHub Desktop.
Save gerdr/4462564 to your computer and use it in GitHub Desktop.
use v6;
# see http://catb.org/jargon/html/A/ASCII.html
# excludes _:. as these are allowed in HTML IDs
my %table = map &uc, qw{{
! bang
" dquote
# sharp
$ dollar
% percent
& amper
' quote
( paren
) thesis
* star
+ plus
, comma
- dash
/ slash
; semi
< bra
> ket
= equals
? query
@ at
[ square
] unsquare
\ bslash
^ hat
` bquote
{ brace
} unbrace
| bar
~ tilde
}};
%table{' '} = '';
# FIXME: eval is evil
my $re = eval "/<[$_]> || <-[$_]>+/" given %table.keys.map('\\' ~ *).join;
# use trans?
sub mangle($_) { .comb($re).map({ %table{$_} // $_ }).join('-') }
say mangle $_ for @*ARGS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment