Skip to content

Instantly share code, notes, and snippets.

@LadyAleena
Created May 10, 2020 02:24
Show Gist options
  • Save LadyAleena/9516ea9bfdb5999bbf1ed6444fe8115c to your computer and use it in GitHub Desktop.
Save LadyAleena/9516ea9bfdb5999bbf1ed6444fe8115c to your computer and use it in GitHub Desktop.
LA's textify subroutine
sub textify {
my ($text, $opt) = @_;
my $root_link = base_path('link');
$text =~ s/$root_link\///;
$text =~ s/_/ /g;
$text =~ s/(?<!Rev\s)\b([DMSJ][rsx]|Mrs|Rev)\b(?!\.)/$1./g;
$text =~ s/\s&\s/ &amp; /g;
$text =~ s/\.{3}/&#8230;/g;
$text =~ s/(\w|\b|\s|^)'(\w|\b|\s|$)/$1&#700;$2/g;
$text =~ s/<.+?>//g unless ($opt->{'html'} && $opt->{'html'} =~ /^[ytk1]/);
$text =~ s/\s\(.*?\)$// unless ($opt->{'parens'} && $opt->{'parens'} =~ /^[ytk1]/);
$text =~ s/\.\w{2,5}?$// unless $text =~ /\.(?:com|net|org)$/;
# $text =~ s/(?<!\A)((?<! )\p{uppercase})/ $1/g; # from Kenosis, kcott, and tye on PerlMonks
return encode('UTF-8',$text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment