【发布时间】:2012-06-01 18:08:34
【问题描述】:
假设我有以下 reST 输入:
Some text ...
:foo: bar
Some text ...
我想最终得到的是这样的字典:
{"foo": "bar"}
我试过用这个:
tree = docutils.core.publish_parts(text)
它确实解析了字段列表,但我最终在tree["whole"]? 中得到了一些伪 XML:
<document source="<string>">
<docinfo>
<field>
<field_name>
foo
<field_body>
<paragraph>
bar
由于tree dict 不包含任何其他有用信息并且只是一个字符串,因此我不确定如何从 reST 文档中解析字段列表。我该怎么做?
【问题讨论】:
标签: python restructuredtext docutils