reStructuredText/Sphinx中文段落内換行導緻生成的HTML多出空格的問題

2016-07-13

Sphinx模塊:

from docutils.nodes import *    def setup(app):      app.connect('doctree-resolved', process_chinese_paragraph)    class ParagraphVisitor(NodeVisitor):      def dispatch_visit(self, node):          if isinstance(node, TextElement):              for i in range(len(node.children)):                  if type(node[i]) == Text:                      node[i] = Text(node[i].astext().replace('
', '').replace('
', ''))    def process_chinese_paragraph(app, doctree, docname):      pv = ParagraphVisitor(doctree)      doctree.walk(pv)  
作用:輸出時删去源文件行長限制下的文本格式性換行符。因為浏覽器會将此類換行解釋為空格,于英文等無礙,而于中文則有礙觀瞻。


http://m.juhua625748.cn|http://wap.juhua625748.cn|http://www.juhua625748.cn||http://juhua625748.cn