Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import regex as re
- with open(sys.argv[1], encoding='utf8') as f:
- txt = f.read()
- pattern = re.compile(r'([\p{IsHan}]+)(《[\p{IsHira}\p{IsKatakana}]+》)', re.UNICODE)
- output = pattern.sub(r'<ruby>\1<rt>\2</rt></ruby>', txt).replace("|","").replace("《","").replace("》","").replace("\n","</p><p>")
- print(output)
- with open('out.html', 'w') as f:
- f.write('<html><style>html {writing-mode: vertical-rl; text-orientation: upright;} body { background-color: SeaShell;}</style><body><p>'+output+'</p></body></html>')
- print('DONE!')
Advertisement
Add Comment
Please, Sign In to add comment