我可以将“Smartypants”添加到重构文本中吗?

问题描述 投票:0回答:3

我使用restructedText,并且我喜欢smartypants 为Markdown 所做的事情。有没有办法为 restructedText 启用相同的功能?

python restructuredtext
3个回答
2
投票

你尝试过smartypants.py吗?我不知道它的实现效果如何,更不用说它对于您的特定用例的效果如何,但它似乎确实准确地针对您的目标,一些 ascii 结构的 unicode 化(但是,它在 HTML 上运行,所以我猜你可以在

restructuredText
或任何其他“HTML生产者”组件之后运行它。

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


1
投票

正如 Alex Martelli 所说,smartyPants 就是我所需要的。但是,我正在寻找有关如何使用它的更详细信息。因此,这里有一个 Python 脚本,它读取第一个命令行参数中指定的文件,使用 Pygments 进行

sourcecode
将其转换为 HTML,然后将其传递给 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

0
投票

自版本 0.10 (2012-12-16) 起,就有本机支持:您可以告诉 Docutils 使用 smart-quotes 设置来“教育”引号。

© www.soinside.com 2019 - 2024. All rights reserved.