-
-
Save hasenj/ed87963feb6cd2e50b71 to your computer and use it in GitHub Desktop.
a python script for writing furigana in markdown
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
import fileinput | |
import re | |
import sys | |
``` | |
eg. [東京]{とうきょう} -> <ruby>東京<rp>(</rp><rt>とうきょう</rt><rp>)</rp></ruby> | |
``` | |
def furiganize(line): | |
# (?<!\\) means don't match if preceeded by a backslash | |
return re.sub(ur'(?<!\\)\[(.*?)\]\{(.*?)\}', ur'<ruby>\1<rp>(</rp><rt>\2</rt><rp>)</rp></ruby>', line.rstrip()) | |
for line in fileinput.input(sys.argv[1:], inplace=True): | |
print(furiganize(line)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment