2010-08-19 41 views

回答

1

正如Alex Martelli所说,smartyPants就是我所需要的。不过,我正在寻找一些关于如何使用它的更详细的信息。因此,下面是一个Python脚本,它读取第一个命令行参数中指定的文件,将其转换为HTML,使用Pygments代替sourcecode,然后通过smartypants将其传递给美化。

#!/usr/bin/python 
# EASY-INSTALL-SCRIPT: 'docutils==0.5','rst2html.py' 
""" 
A minimal front end to the Docutils Publisher, producing HTML. 
""" 

try: 
    from ulif.rest import directives_plain 
    from ulif.rest import roles_plain 
    from ulif.rest import pygments_directive 

    import locale 
    locale.setlocale(locale.LC_ALL, '') 
except: 
    pass 

from docutils.core import publish_doctree, publish_from_doctree 
from smartypants import smartyPants 
import sys 


description = ('Personal docutils parser with extra features.') 

doctree = publish_doctree(file(sys.argv[1]).read()) 
result = publish_from_doctree(doctree, writer_name='html') 
result = smartyPants(result) 
print result 
2

你试过smartypants.py?我不知道它的实现效果如何,更不用说它对于特定用例的效果如何,但它似乎确实针对您的目标,对一些ascii构造进行unicode化(但是,它运行在HTML上,所以我猜你可以在restructuredText之后运行它或其他任何“HTML制作者”组件)。

如果这对你不太好,用户已经提交patch到python-markdown2,他称之为“这个SmartyPants补丁” - 它已被接受,并且自从一个月前它是当前源树的一部分python-markdown2(r259或更好)。这可能会提供更流畅的航行(例如,如果您只是将python-markdown2构建为只读svn tree)。或者,您可以等待下一个可下载的版本(自5月以来没有一个版本,并且这个补丁在7月中旬被接受),但是谁知道何时会发生。

相关问题