【问题标题】:Can I add "Smartypants" to restructuredText?我可以在 restructuredText 中添加“Smartypants”吗?
【发布时间】:2010-08-19 23:22:04
【问题描述】:

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

【问题讨论】:

  • 看起来你在传输过程中被切断了......:P
  • @Nick:谢谢。我什至不知道我想说什么。

标签: python restructuredtext


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    正如 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-09
      • 2016-08-14
      • 2015-10-23
      • 2021-07-27
      • 2020-04-20
      • 2012-03-30
      • 1970-01-01
      相关资源
      最近更新 更多