5

我使用 restructuredText,我喜欢 smartypants 为 Markdown 所做的。有没有办法为 restructuredText 启用相同的功能?

4

2 回答 2

2

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

如果这对您不起作用,则用户已向 python-markdown2 提交了一个补丁,他称之为“此 SmartyPants 补丁”——它已被接受,并且自一个月前以来它是 python-markdown2 当前源代码树的一部分(r259或更好)。这可能会提供更顺畅的航行(例如,如果您只是将 python-markdown2 构建为只读svn 树)。或者,您可以等待下一个可下载版本(自 5 月以来一直没有,并且此补丁在 7 月中旬被接受),但谁知道什么时候会发生。

于 2010-08-20T02:09:56.340 回答
1

正如 Alex Martelli 所说,我需要 smartyPants。但是,我正在寻找有关如何使用它的更详细的信息。所以这是一个 Python 脚本,它读取第一个命令行参数中命名的文件,将其转换为 HTML,使用 Pygments for 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
于 2010-08-22T01:42:43.110 回答