我使用restructuredText,我喜欢smartypants为Markdown做的事情。有没有办法为restructuredText启用同样的功能?
发布于 2010-08-22 09:42:43
正如Alex Martelli所说,smartyPants就是我所需要的。然而,我正在寻找一些关于如何使用它的更详细的信息。下面是一个Python脚本,它读取第一个命令行参数中指定的文件,使用Pygments for 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发布于 2010-08-20 10:09:56
你试过smartypants.py吗?我不知道它的实现有多好,更不用说它对你的特定用例有多好了,但它似乎确实针对你的目标,一些ascii构造的unicode化(然而,它在超文本标记语言上运行,所以我猜你会在restructuredText或任何其他“超文本标记语言生产者”组件之后运行它)。
如果这对您来说不是很好,那么用户已经向python-markdown2提交了一个patch,他称之为“这个SmartyPants补丁”--它已经被接受,并且从一个月前开始它就是python-markdown2 (r259或更好的)当前源码树的一部分。这可能会提供更顺畅的过程(例如,如果您刚刚获得并构建了python-markdown2作为只读svn tree)。或者,你可以等待下一个可下载的版本(自5月以来一直没有一个版本,这个补丁在7月中旬被接受),但谁知道什么时候会发生。
https://stackoverflow.com/questions/3527054
复制相似问题