[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/jp/ - Otaku Culture

Search:


View post   

>> No.45955199 [View]
File: 1.42 MB, 2480x3508, this image had to be further compressed because of 4ddits 4mb limit.jpg [View same] [iqdb] [saucenao] [google]
45955199

I made a small python script to convert Japanese novel TXTs into HTMLs with vertical orientation and proper furigana.
You run it like `python SCRIPTNAME INPUTFILE` and it outputs `out.html`.
I tested it on one volume of Toradora and Shiki.
Yomichan seems to work.
You may need to change the script according to your needs.

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!')

Navigation
View posts[+24][+48][+96]