docutils

Extract field list from reStructuredText

六眼飞鱼酱① 提交于 2019-12-19 03:13:08
问题 Say I have the following reST input: Some text ... :foo: bar Some text ... What I would like to end up with is a dict like this: {"foo": "bar"} I tried to use this: tree = docutils.core.publish_parts(text) It does parse the field list, but I end up with some pseudo XML in tree["whole"]? : <document source="<string>"> <docinfo> <field> <field_name> foo <field_body> <paragraph> bar Since the tree dict does not contain any other useful information and that is just a string, I am not sure how to

ReST strikethrough

旧巷老猫 提交于 2019-12-17 10:19:35
问题 Is it possible to strike text through in Restructured Text? Something that for example renders as a <strike> tag when converted to HTML, like: ReSTructuredText 回答1: I checked the docs better, as suggested by Ville Säävuori, and I decided to add the strikethrough like this: .. role:: strike :class: strike In the document, this can be applied as follows: :strike:`This text is crossed out` Then in my css file I have an entry: .strike { text-decoration: line-through; } 回答2: There is at least

Use sphinx within a serverless model

人走茶凉 提交于 2019-12-13 03:25:31
问题 I am currently using sphinx to automatically generate my documentation site from ReStructuredText files within a bitbucket repo. This is of course all managed/hosted internally but I have been thinking more and more about whether I could switch this out for a more serverless model, using FaaS to generate the site and then a cloud based site hosting for the actual hosting (e.g S3 static site hosting). I was wondering whether it was possible to use sphinx in a programmatic way (e.g within a AWS

Parsing .rst files with Sphinx-specific directives programmatically

痞子三分冷 提交于 2019-12-12 08:05:44
问题 I would like to be able to parse sphinx based rst in Python for further processing and checking. Something like: import sphinx p = sphinx.parse("/path/to/file.rst") do_something_with(p) It seems that something is possible in docutils using the docutils.core.publish_file: publish_file(open("/path/to/file.rst") But that doesn't know anything about sphinx specific directives etc... 回答1: You can use Sphinx Extensions to do custom processing before the final write. There is a very good getting

Sphinx extension: literal block with leading and/or trailing blank lines?

♀尐吖头ヾ 提交于 2019-12-12 01:27:26
问题 As far as I can tell, it is not possible to create a literal text block (e.g. with the code-block directive) that starts or ends with a blank line, because this would be ambiguous with regard to the reStructuredText syntax. That's OK. But now I want to create a custom directive that uses docutils 's literal_block() node, and I want (within the code of my directive) to add empty lines at the beginning and/or end of the directive's contents. Since this isn't possible in reStructuredText syntax,

How to add rel attribute to docutils sphinx reference in HTML output?

我与影子孤独终老i 提交于 2019-12-10 19:44:34
问题 I have a simple extension for the Sphinx documentation utility (my version in use isSphinx-1.1.3-py2.6). Very much like this excellent example by Doug Hellmann. How can I add a rel='bar' attribute to the final HTML for the tag? There seems to be a few ways to do this, but I couldn't find a simple one. Advise and tips are appreciated. The reference nodes are created in this fashion: node = nodes.reference(rawtext, utils.unescape(text), internal=False, refuri=ref, classes=['foocss'], rel='bar',

how to document a single space character within a string in reST/Sphinx?

自闭症网瘾萝莉.ら 提交于 2019-12-10 17:49:37
问题 I've gotten lost in an edge case of sorts. I'm working on a conversion of some old plaintext documentation to reST/Sphinx format, with the intent of outputting to a few formats (including HTML and text) from there. Some of the documented functions are for dealing with bitstrings, and a common case within these is a sentence like the following: Starting character is the blank " " which has the value 0. I tried writing this as an inline literal the following ways: Starting character is the

:synopsis: not working in Sphinx automodule

怎甘沉沦 提交于 2019-12-10 13:58:12
问题 I am using Sphinx, really like it, but it won't pick up the module synopsis. No error or anything, just plain ... nothing. This is the module I am trying to autodocument: # vim: set fileencoding=utf-8 : """ .. module:: CONF :synopsis: Configuration module, tells where data files are. .. moduleauthor:: Mr Anderson <mr@matrix.com> """ This is the Sphinx directive in the ReST index file: .. automodule:: CONF :synopsis: I get all sorts of other wonderful things from Sphinx, so it's not generally

How to add rst format in nodes for directive?

天大地大妈咪最大 提交于 2019-12-10 09:25:41
问题 How I can use rst in nodes? For example I want to output icluded file about.rst class Foo(Directive): def run(self): return [ nodes.Text("**adad**"), # <-- Must be a bold text nodes.Text(".. include:: about.rst"), # <-- Must include file ] 回答1: You can construct a ViewList of your raw rst data (one line per entry), get Sphinx to parse that content, and then return the nodes Sphinx gives you. The following worked for me: from docutils import nodes from docutils.statemachine import ViewList

Insert a link into bold text in reStructuredText

戏子无情 提交于 2019-12-09 14:16:23
问题 I try to insert a link into bold text in reStructuredText but failed. This is my rst source: **Lorem ipsum dolor sit amet, `consectetur <http://www.example.com>`_ adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.** but I got: <strong>Lorem ipsum dolor sit amet, `consectetur <http://www.example.com>`_ adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</strong> I want to get this: <strong>Lorem ipsum dolor sit amet, <a href=