2010-08-19 65 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月中旬被接受),但是誰知道何時會發生。

相關問題