|

楼主 |
发表于 2007-5-18 20:33:15
|
显示全部楼层
OK, 特地说明一下,本patch不是为了解决所有的gnochm中文显示相关问题,它只能解决我在背景中提到的charset未设置的情况,其他诸如左侧列表显示不正确还需要作新的补丁.(见贴图)
to supernatural:
只要装上了gnochm,源代码就是你的可执行文件/usr/bin/gnochm,python写的,很容易看懂,最好不要直接改为gbk, 那样就只能针对简体中文了(何况还有gb18030), utf8才是正道
ps: 代码其实改动微乎其微,不妨将patch贴出,方便大家指正:- --- /usr/bin/gnochm 2006-12-13 23:33:47.000000000 +0800
- +++ gnochm-0.9.9-addcharset 2007-05-18 21:31:37.000000000 +0800
- @@ -67,6 +67,7 @@
-
- #import gc
-
- +html_charset='<meta http-equiv="Content-Type" content="text/html; charset="%s">'
- html_text='<html><head></head><body><center>%s</center></body></html>'
- syn_image_html='<html><head></head><body><img src="%s"></body></html>'
-
- @@ -287,7 +288,7 @@
- self.param = ""
- self.add_level = 0
- self.model = model
- - self.icon = self.ICON_TOPIC //此处是因为作者不小心留了个\t符号
- + self.icon = self.ICON_TOPIC
- self.linklist = {}
- #self.column = 0
-
- @@ -322,7 +323,7 @@
- #print ' ' * self.column, ' Local=', y
- elif (self.param == "merge"):
- self.in_obj = 0
- - elif (self.param == "new"): //此处是因为作者不小心留了个\t符号
- + elif (self.param == "new"):
- self.icon = self.ICON_NEW
- #elif (self.param == "imagenumber") and (int(y) % 2 == 0):
- # self.icon = self.ICON_NEW
- @@ -1046,6 +1047,13 @@
- print_log('to_utf8: Error converting %s' % text)
- return text
- return text
- +
- + def get_html_charset(self, f):
- + match = re.search('charset=(?P<cs>[a-zA-Z0-9_-]*)', f)
- + if match:
- + return match.group('cs')
- + else:
- + return None
-
- def close_all(self):
- if len(self.chmfiles) > 0:
- @@ -1114,6 +1122,9 @@
- ftype = mime.split('/')[0]
- if ftype == 'image':
- f = syn_image_html % pathname
- + if not self.get_html_charset(f):
- + self.document.write_stream(html_charset % 'utf-8')
- + f = self.to_utf8(f);
- self.document.write_stream(f)
- self.document.close_stream()
- self.chmfiles[-1].directory = os.path.dirname(pathname)
- @@ -1352,6 +1363,9 @@
- ftype = mime.split('/')[0]
- if ftype == 'image':
- f = syn_image_html % pathname
- + if not self.get_html_charset(f):
- + self.document.write_stream(html_charset % 'utf-8')
- + f = self.to_utf8(f)
- self.document.write_stream(f)
- self.document.close_stream()
- self.handle_anchors(flink)
- @@ -1639,11 +1653,13 @@
- # history stack and have it removed as soon as
- # the original url gets shown
- self.document.open_stream('text/html')
- + self.document.write_stream(html_charset % 'utf-8')
- html_buffer = re.sub(r'&', r'&', f)
- html_buffer = re.sub(r'<', r'<', html_buffer)
- html_buffer = re.sub(r'>', r'>', html_buffer)
- html_buffer = re.sub(r"'", r''', html_buffer)
- html_buffer = re.sub(r'"', r'"', html_buffer)
- + html_buffer = self.to_utf8(html_buffer)
- self.document.write_stream(html_buffer)
- self.document.close_stream()
- self.statusbar.push(_('Viewing source for %s') % lasturl)
复制代码 |
|