Skip to content

Instantly share code, notes, and snippets.

@hasenj
Forked from huangziwei/markdown_furigana.py
Last active February 24, 2016 18:04
Show Gist options
  • Save hasenj/ed87963feb6cd2e50b71 to your computer and use it in GitHub Desktop.
Save hasenj/ed87963feb6cd2e50b71 to your computer and use it in GitHub Desktop.
a python script for writing furigana in markdown
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