我正在使用Python中的CMS,它使用reStructuredText(通过docutils)来格式化内容.我的很多内容都是从其他来源导入的,通常以未格式化的文本文档的形式出现.reST对此非常有用,因为默认情况下它使一切看起来都非常清晰.
但是,我遇到的一个问题是,我在网络服务器上将警告转储到stderr 并 注入我的页面内容.例如,我在网页上收到如下警告:
系统消息:警告/ 2(,第296行); 反向链接
我的问题是:如何抑制,禁用或重定向这些警告?
理想情况下,我很乐意将这些内容写入日志文件中,但如果有人可以告诉我如何关闭警告并将其注入我的内容中,那么这将是完美的.
负责将reST解析为HTML的代码:
from docutils import core
import reSTpygments
def reST2HTML( str ):
parts = core.publish_parts(
source = str,
writer_name = 'html')
return parts['body_pre_docinfo'] + parts['fragment']
Run Code Online (Sandbox Code Playgroud) 我希望能够在Python中解析基于sphinx的rst进行进一步处理和检查.就像是:
import sphinx
p = sphinx.parse("/path/to/file.rst")
do_something_with(p)
Run Code Online (Sandbox Code Playgroud)
似乎在使用docutils.core.publish_file的docutils中可以实现某些功能:
publish_file(open("/path/to/file.rst")
Run Code Online (Sandbox Code Playgroud)
但是,这对sphinx特定指令等一无所知......
我想采用以下包含替换定义的重构文本片段:
text = """
|python|
.. |python| image:: python.jpg
"""
Run Code Online (Sandbox Code Playgroud)
并解析定义,以便显示替换文本:
resolved_text = """
.. image:: python.jpg
"""
Run Code Online (Sandbox Code Playgroud)
在docutils或其他模块中是否有可以执行此操作的函数或实用程序?
我习惯使用Sphinx进行C++和Python项目.我刚刚在Clojure开始了一个项目,我想重新使用我的Sphinx/reStructuredText技能来记录我的Clojure代码.由于Clojure 没有内置域,我开始写一个.
具有讽刺意味的是,Sphinx的文档对于编写扩展程序毫无帮助.所以,从Python和Javascript的内置模式开始,我已经有了一些基本元素.我可以使用以下指令编写函数文档:
.. clj:ns:: clojure.core
.. clj:fn:: (filter f coll)
:param f: predicate
:param coll: collection
Built-in!
Run Code Online (Sandbox Code Playgroud)
但是,HTML输出会生成C/Python样式的签名.前面的示例生成如下内容:
filter(f, coll)
Parameters: * f - predicate
* coll - collection
Built-in!
Run Code Online (Sandbox Code Playgroud)
我宁愿以lisp-ish形式获得签名:
(filter f coll)
Parameters: * f - predicate
* coll - collection
Built-in!
Run Code Online (Sandbox Code Playgroud)
生成签名的代码似乎一直到docutils.addnodes模块.如何让Sphinx使用Sphinx语法生成HTML?它可以用模板完成,还是我需要通过整个构建器系统来执行此操作?
假设我有以下reST输入:
Some text ...
:foo: bar
Some text ...
Run Code Online (Sandbox Code Playgroud)
我想最终得到的是这样一个字典:
{"foo": "bar"}
Run Code Online (Sandbox Code Playgroud)
我试着用这个:
tree = docutils.core.publish_parts(text)
Run Code Online (Sandbox Code Playgroud)
它确实解析了字段列表,但我最终得到了一些伪XML tree["whole"]?:
<document source="<string>">
<docinfo>
<field>
<field_name>
foo
<field_body>
<paragraph>
bar
Run Code Online (Sandbox Code Playgroud)
由于treedict不包含任何其他有用的信息,而且只是一个字符串,我不知道如何解析reST文档中的字段列表.我该怎么办?
我正在尝试使用latexpdf输出将编号数字用于我的Sphinx文档项目.我在这里安装了Sphinx numfig.py扩展程序https://bitbucket.org/arjones6/sphinx-numfig
但是,每当我使用:num:标签时,它应该提供与图形编号I的交叉引用,而不是得到以下内容
RST
.. _fig_logo:
.. figure:: logo.*
Example of a figure
Reference to logo :num:`figure #fig_logo`
Run Code Online (Sandbox Code Playgroud)
生成输出:
参考徽标图?
难道我做错了什么?
我想将.rst文件解析为.html文件,以显示为网页.我正在使用金字塔,我没有找到任何有关如何在python代码中使用docutils并使其写入缓冲区的快速帮助.
任何人都有任何链接到一个简单的教程或任何其他建议如何做到这一点?
考虑一个带有这个骨架的 reStructuredText 文档:
Main Title
==========
text text text text text
Subsection
----------
text text text text text
.. my-import-from:: file1
.. my-import-from:: file2
Run Code Online (Sandbox Code Playgroud)
该my-import-from指令由特定于文档的 Sphinx 扩展提供,它应该读取作为其参数提供的文件,解析嵌入其中的 reST,并将结果作为当前输入文件中的一个部分注入。(类似于 autodoc,但文件格式不同。)我现在的代码如下所示:
class MyImportFromDirective(Directive):
required_arguments = 1
def run(self):
src, srcline = self.state_machine.get_source_and_line()
doc_file = os.path.normpath(os.path.join(os.path.dirname(src),
self.arguments[0]))
self.state.document.settings.record_dependencies.add(doc_file)
doc_text = ViewList()
try:
doc_text = extract_doc_from_file(doc_file)
except EnvironmentError as e:
raise self.error(e.filename + ": " + e.strerror) from e
doc_section = nodes.section()
doc_section.document = self.state.document
# report line numbers within the nested …Run Code Online (Sandbox Code Playgroud) 有没有办法实现以下目标?
.rst文件,其中多种语言的翻译共存.html最好是文件).
rst2html但是也欢迎其他常用工具我想到的用例.在foo.rst(我不是说我想要这些标签):
..lang_en:
She likes spinach the best.
..lang_de:
Sie mag am besten Spinat.
Run Code Online (Sandbox Code Playgroud)
正如我所提到的,结果将是单个foo.html或一组foo_en.html和foo_de.html.
我在PyCharm中有一个Python项目,我想从我的Python代码和文档字符串中自动生成API文档(以HTML的形式).
根据此页面,有许多工具可以生成Python API文档:
该页面还注意到以下工具"流程文档":
该PyCharm文件说的是docutils的狮身人面像和可以使用"产生格式化的API文档".但是,这似乎是不正确的,因为它们的配置表明这些工具只处理*.rst文件,而不处理*.py文件.
我的问题是:我可以使用PyCharm的DocUtils或Sphinx功能来生成API文档吗?
如果做不到这一点,我可以使用PyCharm的任何功能来做到这一点吗?
如果不这样做,有没有任何工具可以与PyCharm很好地集成?
docutils ×10
python ×8
clojure ×1
latex ×1
multilingual ×1
pycharm ×1
pyramid ×1
rst2html.py ×1