views:

64

answers:

2

I use restructuredText, and I like what smartypants does for Markdown. Is there a way to enable the same thing for restructuredText?

+2  A: 

Have you tried smartypants.py? I don't know how well it's implemented, much less how well it works for your specific use cases, but it does seem to target exactly your goal, unicode-ification of some ascii constructs (however, it runs on HTML, so I guess you'd run it after restructuredText or whatever other "producer of HTML" component).

If that doesn't work well for you, a user has submitted a patch to python-markdown2 which he calls "this SmartyPants patch" -- it's been accepted and since a month ago it's part of the current source tree of python-markdown2 (r259 or better). That may offer smoother sailing (e.g. if you just get and built python-markdown2 as a read-only svn tree). Or, you could wait for the next downloadable release (there hasn't been one since May and this patch was accepted in mid-July), but who knows when that'll happen.

Alex Martelli
+1  A: 

As Alex Martelli says, smartyPants is what I need. However, I was looking for a little more detailed info on how to use it. So here's a Python script that reads the file named in the first command line argument, converts it to HTML, using Pygments for sourcecode, and then passses it through smartypants for prettifying.

#!/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
Paul Biggar