-
Notifications
You must be signed in to change notification settings - Fork 0
/
_cv_hhx.py
56 lines (38 loc) · 1.04 KB
/
_cv_hhx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
#
# Sphinxから吐き出したhh[ck]ファイルを
# 日本語用のHTML(SJIS)に書き換えるよ(Win環境用)
#
# 前提としてSphinxプロジェクト内で"make htmlhelp"していること
# Sphinx プロジェクトの言語指定は en
# (確認: Windows Vista/Python 2.6/Sphinx 1.0.7)
import os
import sys
import re
# conf.py をインポート
import conf
cvpaths = [os.path.join(r'_build\htmlhelp',conf.htmlhelp_basename + '.hhc') ,
os.path.join(r'_build\htmlhelp',conf.htmlhelp_basename + '.hhk')]
# iso10646エンコードから、mcbsに変換
def foo(match):
n = int(match.groups(0)[0])
try:
s = unichr(n).encode('mbcs')
except:
s= "?"
return s
#
p= re.compile(r'\&\#(\d*)\;')
for cvpath in cvpaths:
fi = open(cvpath,'r')
buf = []
while 1:
line = fi.readline()
if not line:
break
buf.append(p.sub(foo,line))
fi.close()
fo = open(cvpath,'w')
for x in buf:
fo.write(x)
fo.close()