Reference¶
rst2html5_ Module¶
-
class
rst2html5_.
ElemStack
(settings)[source]¶ Helper class to handle nested contexts and indentation
The doctree must be adjusted before translation begins since in-place tree modifications doesn’t work.
The footer must be relocated to the bottom of the doctree in order to be translated at the right position.
Override to apply the transform to the document tree.
-
class
rst2html5_.
HTML5Translator
(document)[source]¶ -
default_departure
(node)[source]¶ Create the node’s corresponding HTML5 element and combine it with its stored context.
-
depart_colspec
(node)[source]¶ <col /> tags are not generated anymore because they’re pretty useless since they cannot receive any attribute from a rst table. Anyway, there are better ways to apply styles to columns. See http://csswizardry.com/demos/zebra-striping/ for example.
Nevertheless, if a colspec node with a “stub” attribute indicates that the column should be a th tag.
-
depart_enumerated_list
(node)[source]¶ Ordered list. It may have a preffix and suffix that must be handled by CSS3 and javascript to be presented as intended.
-
parse
(node)[source]¶ Get tag name, indentantion and correct attributes of a node according to its class
-
visit_citation_reference
(node)[source]¶ Instead of a typical visit_reference call this def is required to remove the backref id that is included but not used in rst2html5.
-
visit_line_block
(node)[source]¶ Line blocks use <pre>. Lines breaks and spacing are reconstructured based on line_block_level
-
-
class
rst2html5_.
HTML5Writer
[source]¶ -
-
translate
()[source]¶ Do final translation of self.document into self.output. Called from write. Override in subclasses.
Usually done with a docutils.nodes.NodeVisitor subclass, in combination with a call to docutils.nodes.Node.walk() or docutils.nodes.Node.walkabout(). The
NodeVisitor
subclass must support all standard elements (listed in docutils.nodes.node_class_names) and possibly non-standard elements used by the current Reader as well.
-
-
class
rst2html5_.
WrapTopTitle
(document, startnode=None)[source]¶ If the top element of a document is a title, wrap all the document’s children within a section.
For example:
<span class="p">..</span> <span class="nt">_outer_target:</span> <span class="p">..</span> <span class="nt">_inner_target:</span> <span class="gh">Title 1</span> <span class="gh">=======</span> The targets outer_target_ and inner_target_ point both to Title 1
The previous snippet should be transformed from:
<span class="nt"><document</span> <span class="na">ids=</span><span class="s">"title-1 inner-target outer-target"</span> <span class="err">\</span> <span class="na">names=</span><span class="s">"title\ 1 inner_target outer_target"</span> <span class="na">source=</span><span class="s">"internal_link_2.rst"</span> <span class="err">\</span> <span class="na">title=</span><span class="s">"Title 1"</span><span class="nt">></span> <span class="nt"><title></span> Title 1 <span class="nt"><target</span> <span class="na">refid=</span><span class="s">"outer-target"</span><span class="nt">></span> <span class="nt"><target</span> <span class="na">refid=</span><span class="s">"inner-target"</span><span class="nt">></span> <span class="nt"><paragraph></span> The targets <span class="nt"><reference</span> <span class="na">name=</span><span class="s">"outer_target"</span> <span class="na">refid=</span><span class="s">"outer-target"</span><span class="nt">></span> outer_target and <span class="nt"><reference</span> <span class="na">name=</span><span class="s">"inner_target"</span> <span class="na">refid=</span><span class="s">"inner-target"</span><span class="nt">></span> inner_target point both to Title 1
into:
<span class="nt"><document</span> <span class="na">source=</span><span class="s">"internal_link_2.rst"</span><span class="nt">></span> <span class="nt"><section</span> <span class="na">ids=</span><span class="s">"title-1 inner-target outer-target"</span> <span class="na">names=</span><span class="s">"title\ 1 inner_target outer_target"</span><span class="nt">></span> <span class="nt"><title></span> Title 1 <span class="nt"><paragraph></span> The targets <span class="nt"><reference</span> <span class="na">name=</span><span class="s">"outer_target"</span> <span class="na">refid=</span><span class="s">"outer-target"</span><span class="nt">></span> outer_target and <span class="nt"><reference</span> <span class="na">name=</span><span class="s">"inner_target"</span> <span class="na">refid=</span><span class="s">"inner-target"</span><span class="nt">></span> inner_target point both to Title 1
docutils¶
Classes¶
-
class
docutils.nodes.
NodeVisitor
(document)[source]¶ “Visitor” pattern [GoF95] abstract superclass implementation for document tree traversals.
Each node class has corresponding methods, doing nothing by default; override individual methods for specific and useful behaviour. The dispatch_visit() method is called by Node.walk() upon entering a node. Node.walkabout() also calls the dispatch_departure() method before exiting a node.
The dispatch methods call “
visit_
+ node class name” or “depart_
+ node class name”, resp.This is a base class for visitors whose
visit_...
&depart_...
methods should be implemented for all node types encountered (such as for docutils.writers.Writer subclasses). Unimplemented methods will raise exceptions.For sparse traversals, where only certain node types are of interest, use subclass SparseNodeVisitor instead. When (mostly or entirely) uniform processing is desired, subclass GenericNodeVisitor.
[GoF95] Gamma, Helm, Johnson, Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading, MA, USA, 1995.
Methods¶
-
Writer.
translate
()[source]¶ Do final translation of self.document into self.output. Called from write. Override in subclasses.
Usually done with a docutils.nodes.NodeVisitor subclass, in combination with a call to docutils.nodes.Node.walk() or docutils.nodes.Node.walkabout(). The
NodeVisitor
subclass must support all standard elements (listed in docutils.nodes.node_class_names) and possibly non-standard elements used by the current Reader as well.
-
NodeVisitor.
dispatch_visit
(node)[source]¶ Call self.”
visit_
+ node class name” with node as parameter. If thevisit_...
method does not exist, call self.unknown_visit.
-
NodeVisitor.
dispatch_departure
(node)[source]¶ Call self.”
depart_
+ node class name” with node as parameter. If thedepart_...
method does not exist, call self.unknown_departure.
-
Node.
walk
(visitor)[source]¶ Traverse a tree of Node objects, calling the dispatch_visit() method of visitor when entering each node. (The walkabout() method is similar, except it also calls the dispatch_departure() method before exiting each node.)
This tree traversal supports limited in-place tree modifications. Replacing one node with one or more nodes is OK, as is removing an element. However, if the node removed or replaced occurs after the current node, the old node will still be traversed, and any new nodes will not.
Within
visit
methods (anddepart
methods for walkabout()), TreePruningException subclasses may be raised (SkipChildren, SkipSiblings, SkipNode, SkipDeparture).Parameter visitor: A NodeVisitor object, containing a
visit
implementation for each Node subclass encountered.Return true if we should stop the traversal.
-
Node.
walkabout
(visitor)[source]¶ Perform a tree traversal similarly to Node.walk() (which see), except also call the dispatch_departure() method before exiting each node.
Parameter visitor: A NodeVisitor object, containing a
visit
anddepart
implementation for each Node subclass encountered.Return true if we should stop the traversal.
Genshi¶
-
genshi.builder.
tag
¶ Global ElementFactory bound to the default namespace.
Type: ElementFactory alias of
genshi.builder.
Bibliography¶
- [GoF95] Gamma, Helm, Johnson, Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading, MA, USA, 1995.