【问题标题】:Process string using sphinx使用 sphinx 处理字符串
【发布时间】:2012-01-26 19:14:52
【问题描述】:

我想知道是否可以使用 sphinx 在 python 中处理字符串。基本上,我想将包含重组文本的字符串传递给 sphinx,然后生成相应的 HTML 输出。我的意思是这样的

import sphinx.something
s = 'some restructured text'
html_out = sphinx.something(s)

但是,我找不到任何类似的东西。那么,这是否可能,如果可以,如何做到这一点?

【问题讨论】:

  • 也许看看 docutils,Sphinx 是基于它的。
  • 谢谢,但我想我真的需要 sphinx 服务。
  • 你想做什么?在 Sphinx 中处理一个字符串并没有什么意义,因为 Sphinx 是关于文档之间的链接等。
  • 但即便如此,我应该能够处理第一个字符串,不是吗?我正在尝试为 rst 编写一个简单的编辑器,因此我会从文本窗口中获取字符串,对其进行编译,然后在 HTML 查看器中显示输出。

标签: python import python-sphinx


【解决方案1】:

我见过的最快的解决方案是:

from docutils.examples import html_body

def rst(rstStr):
return html_body(rstStr, input_encoding='utf-8', 
                 output_encoding='utf-8').strip()

我会对更好的解决方案感兴趣..

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 2012-05-21
    相关资源
    最近更新 更多