docutils

Extracting blocks of text from ReST documents by :ref:?

对着背影说爱祢 提交于 2019-12-08 05:59:34
问题 I have some reStructuredText documentation. I would like to use snippets from it in online help. It seems like one approach would be to 'snip' out pieces of markup by reference, e.g. .. _my_boring_section: Introductory prose ------------------ blah blah blah .. _my_interesting_section: About this dialog ----------------- talk about stuff which is relevant in contextual help How could I use python/docutils/sphinx to extract the markup for the _my_interesting_section marker? 回答1: I'm not sure

Extending rst container to output extra div attributes

风流意气都作罢 提交于 2019-12-07 04:47:11
问题 I'm starting to use pelican with reStructuredText rst page format. I have custom javascript (jQuery) things that I'd like to control with div attributes like data-default-tpl="basename" with nested content. What to extend and what. I've looked at Directives and nodes , but I just can't wrap my head around how to do it. .. rstdiv:: class1 class2 :name: namessid :extra: thisIsMyextra .. rstdiv:: nested class3 :name: nestedid :extra: data-default-tpl="basename" some text .. container:: This is

Extracting blocks of text from ReST documents by :ref:?

蹲街弑〆低调 提交于 2019-12-06 16:40:59
I have some reStructuredText documentation. I would like to use snippets from it in online help. It seems like one approach would be to 'snip' out pieces of markup by reference, e.g. .. _my_boring_section: Introductory prose ------------------ blah blah blah .. _my_interesting_section: About this dialog ----------------- talk about stuff which is relevant in contextual help How could I use python/docutils/sphinx to extract the markup for the _my_interesting_section marker? Chris I'm not sure how you could do this other than subclassing and customising the Docutils parser. If you just need the

How to add rst format in nodes for directive?

纵饮孤独 提交于 2019-12-05 12:09:59
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 ] 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 from sphinx.util.compat import Directive from sphinx.util.nodes import nested_parse_with_titles class Foo

Insert a link into bold text in reStructuredText

自闭症网瘾萝莉.ら 提交于 2019-12-03 22:37:55
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="http://www.example.com">consectetur</a> adipisicing elit, sed do eiusmod tempor incididunt ut labore et

Extract field list from reStructuredText

天大地大妈咪最大 提交于 2019-11-30 21:02:41
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 parse the field list out of the reST document. How would I do that? Chris You can try to use something

Conditional toctree in Sphinx

浪子不回头ぞ 提交于 2019-11-30 20:52:03
I want to do multiple versions of a documentation, which differ in the sections that are included. To achieve this I would usually use either the only directive or the ifconfig extension. However, I cannot use any of those in combination with the toctree directive. What I basically want is something like this: .. toctree:: :maxdepth: 2 intro strings datatypes numeric .. only:: university complex Is there a way to do that? As far as I know there is no way to do what you would like. I have been struggling with the same issue, see https://github.com/sphinx-doc/sphinx/issues/1717 . The reason is

Overriding the default field name limit in sphinx/docutils

感情迁移 提交于 2019-11-30 06:59:05
I am using sphinx for generating html documentation for a project. I make extensive use of field lists . When generating html, each label/value pair is rendered as a single table row with two cells if the lenght of the label is at most 14 characters. If the label of one pair is longer than 14 characters, the label/values are rendered as two table rows. I want to increase the wrapping limit to a larger value (e.g. 40). I have found that the limit is controlled by the --field-name-limit option of docutils. However, I can't find how to set this value through sphinx. I have created a docutils.conf

Conditional toctree in Sphinx

我怕爱的太早我们不能终老 提交于 2019-11-29 14:27:16
问题 I want to do multiple versions of a documentation, which differ in the sections that are included. To achieve this I would usually use either the only directive or the ifconfig extension. However, I cannot use any of those in combination with the toctree directive. What I basically want is something like this: .. toctree:: :maxdepth: 2 intro strings datatypes numeric .. only:: university complex Is there a way to do that? 回答1: My previous answer fails if you have hierarchies of table of

Parsing reStructuredText into HTML

风流意气都作罢 提交于 2019-11-28 15:57:50
I'm making a framework in which I let developers describe their package using reStructuredText. I want to parse that reStructuredText into HTML so I can show it in a GUI. I'm familiar with the excellent Sphinx, but I've never otherwise parsed reStructuredText. I imagined something like a function that takes a string of reStructuredText, and possibly several additional arguments, and returns a string of HTML. So I looked into Docutils, which is responsible for parsing reStructuredText. I couldn't understand at all how to find this function. Documentation on the web is spotty. Many of the