1- """
1+ """pip
22sphinxnotes.render.pipeline
33~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
1010The Pipline
1111===========
1212
13- 1. Define context: BaseDataSource generates a :class:`pending_node`, which contains:
13+ 1. Define context: BaseContextSource generates a :class:`pending_node`, which contains:
1414
1515 - Context
1616 - Template for rendering data to markup text
1717 - Possible extra contexts
1818
19- See also :class:`BaseDataSource `.
19+ See also :class:`BaseContextSource `.
2020
21212. Render data: the ``pending_node`` nodes will be rendered
2222 (by calling :meth:`pending_node.render`) at some point, depending on
2929 Phases:
3030
3131 :``Phase.Parsing``:
32- Called by BaseDataSource ('s subclasses)
32+ Called by BaseContextSource ('s subclasses)
3333
3434 :``Phase.Parsed``:
3535 Called by :class:`ParsedHookTransform`.
6767
6868class Pipeline (ABC ):
6969 """
70- The core class defines the pipleing of rendering :class:`pending_node`s.
70+ The core class defines the pipleing of rendering
71+ :py:class:`~sphinxnotes.render.pending_node`\ (s).
7172
7273 Subclass is responsible to:
7374
7475 - call ``queue_xxx`` to add pendin nodes into queue.
75- - override :meth:`process_pending_node` to control when a pending node gets
76+ - override :py: meth:`~Pipeline. process_pending_node` to control when a pending node gets
7677 rendered. In this method subclass can also call ``queue_xxx`` to add more
7778 pending nodes.
78- - call :meth:`render_queue` to process all queued nodes and
79+ - call :py: meth:`render_queue` to process all queued nodes and
7980 returns any that couldn't be rendered in the current phase.
8081
8182 See Also:
8283
83- - :class:`BaseDataSource `: Context source implementation and hook for Phase.Parsing
84- - :class:`ParsedHookTransform`: Built-in hook for Phase.Parsed
85- - :class:`ResolvingHookTransform`: Built-in hook for Phase.Resolving
84+ - :py: class:`BaseContextSource `: Context source implementation and hook for Phase.Parsing
85+ - :py: class:`ParsedHookTransform`: Built-in hook for Phase.Parsed
86+ - :py: class:`ResolvingHookTransform`: Built-in hook for Phase.Resolving
8687 """
8788
8889 #: Queue of pending node to be rendered.
@@ -92,18 +93,28 @@ class Pipeline(ABC):
9293
9394 def process_pending_node (self , n : pending_node ) -> bool :
9495 """
95- You can add hooks to pending node here .
96+ This method is called when it is the pending node's turn to be rendered .
9697
9798 Return ``true`` if you want to render the pending node *now*,
98- otherwise it will be inserted to doctree directly andwaiting to later
99- rendering
99+ otherwise it will be inserted to doctree directly and waiting to later
100+ rendering (and this method will be called again.).
101+
102+ You can add hooks to pending node here. or call :py:meth:`~Pipeline.queue_pending_node`
103+ to. You are responsible for inserting it into the doctree themselves if
104+ the node is created by the yourself.
105+
106+ .. note::
107+
108+ Please always call ``super().process_pending_node(n)`` to ensure the
109+ extension functions properly.
100110 """
101111 ...
102112
103113 """Helper method for subclasses."""
104114
105115 @final
106116 def queue_pending_node (self , n : pending_node ) -> None :
117+ """Push a new pending_node to the render queue."""
107118 if not self ._q :
108119 self ._q = []
109120 self ._q .append (n )
@@ -112,6 +123,7 @@ def queue_pending_node(self, n: pending_node) -> None:
112123 def queue_context (
113124 self , ctx : PendingContext | ResolvedContext , tmpl : Template
114125 ) -> pending_node :
126+ """A helper method of :py:meth:`Pipeline.queue_pending_node`."""
115127 pending = pending_node (ctx , tmpl )
116128 self .queue_pending_node (pending )
117129 return pending
@@ -121,8 +133,9 @@ def render_queue(self) -> list[pending_node]:
121133 """
122134 Try rendering all pending nodes in queue.
123135
124- If the timing(Phase) is ok, :class:`pending_node` will be rendered
125- (pending.rendered = True); otherwise, the pending node is unchanged.
136+ If the timing(Phase) is ok, :py:class:`sphinxnotes.render.pending_node`
137+ will be rendered (pending.rendered = True); otherwise, the pending node
138+ is unchanged.
126139
127140 If the pending node is already inserted to document, it will not be return.
128141 And the corrsponding rendered node will replace it too.
@@ -176,9 +189,9 @@ class BaseContextSource(Pipeline):
176189 pipeline.
177190
178191 This class also responsible to render context in Phase.Parsing. So the final
179- implementations MUST be subclass of :class:`SphinxDirective` or
180- : class:`SphinxRole`, which provide the execution context and interface for
181- processing reStructuredText markup.
192+ implementations MUST be subclass of :py: class:`~sphinx.util.docutils. SphinxDirective`
193+ or :py: class:`~sphinx.util.docutils. SphinxRole`, which provide the execution
194+ context and interface forrprocessing reStructuredText markup.
182195 """
183196
184197 """Methods to be implemented."""
@@ -217,6 +230,13 @@ def process_pending_node(self, n: pending_node) -> bool:
217230
218231
219232class BaseContextDirective (BaseContextSource , SphinxDirective ):
233+ """This class generates :py:meth:`sphinxnotes.render.pending_node` in
234+ ``SphinxDirective.run`` method and make sure it can be correctly rendered.
235+
236+ User should implement ``current_context`` and ``current_template`` methods
237+ for providing the construct parameters of pending_node.
238+ """
239+
220240 @override
221241 def run (self ) -> list [nodes .Node ]:
222242 self .queue_context (self .current_context (), self .current_template ())
@@ -232,6 +252,13 @@ def run(self) -> list[nodes.Node]:
232252
233253
234254class BaseContextRole (BaseContextSource , SphinxRole ):
255+ """This class extends generates :py:meth:`sphinxnotes.render.pending_node` in
256+ ``SphinxRole.run`` method and make sure it can be correctly rendered.
257+
258+ User should implement ``current_context`` and ``current_template`` methods
259+ for providing the construct parameters of pending_node.
260+ """
261+
235262 @override
236263 def process_pending_node (self , n : pending_node ) -> bool :
237264 n .inline = True
0 commit comments