Last active
February 21, 2024 16:55
-
-
Save vi/2d6b268cc243c138358f3d1b88120ff5 to your computer and use it in GitHub Desktop.
Simple converter from markdown-style _annotations_ to Unicode combining characters.
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
#!/usr/bin/perl -C63 | |
# Converts | |
# The -quick- _brown_ =fox= ^jumps^ +over+ ~the~ @lazy@ dog. | |
# into | |
# The q̶u̶i̶c̶k̶ b̲r̲o̲w̲n̲ f̳o̳x̳ j̅u̅m̅p̅s̅ o̱v̱e̱ṟ t̴h̴e̴ l̿a̿z̿y̿ dog. | |
# | |
# Implemented by Vitaly "_Vi" Shukela in 2016. Public domain / CC-0. | |
use strict; | |
use warnings; | |
use utf8; | |
$_=' '.(join ' ',@ARGV).' '; | |
sub interleave($$) { | |
my $t=shift; | |
my $r=shift; | |
$t =~ s@\X@$&$r@g; | |
return $t; | |
} | |
s@(?<=\s) \- (?=\w) (.*?) (?<=\w) \- (?=\s|$)@ interleave($1,pack("U*",0x0336)) @gex; # strikethough | |
s@(?<=\s) \~ (?=\w) (.*?) (?<=\w) \~ (?=\s|$)@ interleave($1,pack("U*",0x0334)) @gex; # tildethough | |
s@(?<=\s) \_ (?=\w) (.*?) (?<=\w) \_ (?=\s|$)@ interleave($1,pack("U*",0x0332)) @gex; # underline | |
s@(?<=\s) \= (?=\w) (.*?) (?<=\w) \= (?=\s|$)@ interleave($1,pack("U*",0x0333)) @gex; # double underline | |
s@(?<=\s) \+ (?=\w) (.*?) (?<=\w) \+ (?=\s|$)@ interleave($1,pack("U*",0x0331)) @gex; # dashed underline | |
s@(?<=\s) \^ (?=\w) (.*?) (?<=\w) \^ (?=\s|$)@ interleave($1,pack("U*",0x0305)) @gex; # overline | |
s@(?<=\s) \@ (?=\w) (.*?) (?<=\w) \@ (?=\s|$)@ interleave($1,pack("U*",0x033f)) @gex; # double overline | |
substr($_,0,1)=''; | |
substr($_,-1,1)=''; | |
print $_, "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment