From 782919eb2628e2998860ec7c6ff4b9179e997010 Mon Sep 17 00:00:00 2001 From: Yin Gang Date: Thu, 19 Aug 2021 11:40:43 +0800 Subject: [PATCH] support to run zh-tw.py on Windows, improve the handling of newline and image URLs for zh-tw version --- bin/zh-tw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/zh-tw.py b/bin/zh-tw.py index 20bcaed..b237c56 100755 --- a/bin/zh-tw.py +++ b/bin/zh-tw.py @@ -3,8 +3,8 @@ import os, sys, opencc def convert(src_path, dst_path, cfg='s2twp.json'): converter = opencc.OpenCC(cfg) - with open(src_path, "r") as src, open(dst_path, "w+") as dst: - dst.write("\n".join(converter.convert(line) for line in src)) + with open(src_path, "r", encoding='utf-8') as src, open(dst_path, "w+", encoding='utf-8') as dst: + dst.write("\n".join(converter.convert(line.rstrip()).replace('(img/', '(../img/') for line in src)) print("convert %s to %s" % (src_path, dst_path))