Debian Codegraph @

docs/examples/kitchen-sink/blocks.rst

raw
1 ..
2 Copyright (c) 2021 Pradyun Gedam
3 Licensed under Creative Commons Attribution-ShareAlike 4.0 International License
4 SPDX-License-Identifier: CC-BY-SA-4.0
5
6 ======
7 Blocks
8 ======
9
10 Block Quotes
11 ============
12
13 Block quotes consist of indented body elements:
14
15 My theory by A. Elk. Brackets Miss, brackets. This theory goes
16 as follows and begins now. All brontosauruses are thin at one
17 end, much much thicker in the middle and then thin again at the
18 far end. That is my theory, it is mine, and belongs to me and I
19 own it, and what it is too.
20
21 -- Anne Elk (Miss)
22
23 Epigraph
24 --------
25
26 https://docutils.sourceforge.io/docs/ref/rst/directives.html#epigraph
27
28 .. epigraph::
29
30 My theory by A. Elk. Brackets Miss, brackets. This theory goes
31 as follows and begins now. All brontosauruses are thin at one
32 end, much much thicker in the middle and then thin again at the
33 far end. That is my theory, it is mine, and belongs to me and I
34 own it, and what it is too.
35
36 -- Anne Elk (Miss)
37
38 Pull quotes
39 -----------
40
41 https://docutils.sourceforge.io/docs/ref/rst/directives.html#pull-quote
42
43 .. pull-quote::
44
45 My theory by A. Elk. Brackets Miss, brackets. This theory goes
46 as follows and begins now. All brontosauruses are thin at one
47 end, much much thicker in the middle and then thin again at the
48 far end. That is my theory, it is mine, and belongs to me and I
49 own it, and what it is too.
50
51 -- Anne Elk (Miss)
52
53 Highlights
54 ----------
55
56 https://docutils.sourceforge.io/docs/ref/rst/directives.html#highlights
57
58 .. highlights::
59
60 My theory by A. Elk. Brackets Miss, brackets. This theory goes
61 as follows and begins now. All brontosauruses are thin at one
62 end, much much thicker in the middle and then thin again at the
63 far end. That is my theory, it is mine, and belongs to me and I
64 own it, and what it is too.
65
66 -- Anne Elk (Miss)
67
68 Line Blocks
69 ===========
70
71 https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#line-blocks
72
73 This is a normal text paragraph.
74
75 | This is a line block. It ends with a blank line.
76 | Each new line begins with a vertical bar ("|").
77 | Line breaks and initial indents are preserved.
78 | Continuation lines are wrapped portions of long lines;
79 they begin with a space in place of the vertical bar.
80 | The left edge of a continuation line need not be aligned with
81 the left edge of the text above it.
82
83 | This is a second line block.
84 |
85 | Blank lines are permitted internally, but they must begin with a "|".
86
87 This is a normal text paragraph again.
88
89 Monospace Blocks
90 ================
91
92 Sphinx supports many kinds of monospace blocks. This section is meant to
93 showcase *all* of them that as known to the author of this page, at the time of
94 writing.
95
96 Production List
97 ---------------
98
99 https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-productionlist
100
101 This directive is used to enclose a group of productions. Each production is given on a single line and consists of a name, separated by a colon from the following definition.
102
103 This just shows up as a vanilla ``<pre>``, which is... both nice and a bit
104 annoying.
105
106 .. productionlist::
107 try_stmt: try1_stmt | try2_stmt
108 try1_stmt: "try" ":" `suite`
109 : ("except" [`expression` ["," `target`]] ":" `suite`)+
110 : ["else" ":" `suite`]
111 : ["finally" ":" `suite`]
112 try2_stmt: "try" ":" `suite`
113 : "finally" ":" `suite`
114 : "this-is-intentionally-very-stupidly-long-to-make-sure-that-this-has-a-proper-scrollbar"
115
116 Literal Blocks
117 --------------
118
119 https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#literal-blocks
120
121 contains a block of text where line breaks and whitespace are significant and must be preserved
122
123 This is a normal text paragraph. The next paragraph is a code sample::
124
125 It is not processed in any way, except
126 that the indentation is removed.
127
128 It can span multiple lines.
129
130 This is a normal text paragraph again.
131
132 They can be quoted without indentation::
133
134 >> Great idea!
135 >
136 > Why didn't I think of that?
137
138 .. literalinclude:: ../../../src/pydata_sphinx_theme/__init__.py
139 :language: python
140 :caption: Literal includes can also have captions.
141 :linenos:
142 :lines: 10-20
143
144 Doctest Blocks
145 --------------
146
147 https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#doctest-blocks
148
149 Doctest blocks are interactive Python sessions cut-and-pasted into docstrings. They are meant to illustrate usage by example, and provide an elegant and powerful testing environment via the doctest module in the Python standard library.
150
151 .. note::
152
153 This is fine.
154
155 >>> print('Python-specific usage examples; begun with ">>>"')
156 Python-specific usage examples; begun with ">>>"
157 >>> print("(cut and pasted from interactive Python sessions)")
158 (cut and pasted from interactive Python sessions)
159 >>> print("This is an intentionally very long line because I want to make sure that we are handling scrollable code blocks correctly.")
160 This is an intentionally very long line because I want to make sure that we are handling scrollable code blocks correctly.
161
162 Parsed Literals
163 ---------------
164
165 https://docutils.sourceforge.io/docs/ref/rst/directives.html#parsed-literal-block
166
167 It is equivalent to a line block with different rendering: typically in a typewriter/monospaced typeface, like an ordinary literal block. Parsed literal blocks are useful for adding hyperlinks to code examples.
168
169 .. parsed-literal::
170
171 # parsed-literal test
172 curl -O https://someurl/release-0.1.0.tar-gz
173 echo "This is an intentionally very long line because I want to make sure that we are handling scrollable code blocks correctly."
174
175 Code Block
176 ----------
177
178 https://docutils.sourceforge.io/docs/ref/rst/directives.html#code
179
180 The "code" directive constructs a literal block [containing code].
181
182 This has an alias of ``code-block``.
183
184
185 .. code-block:: python
186 :linenos:
187
188 from typing import Iterator
189
190 # This is an example
191 class Math:
192 @staticmethod
193 def fib(n: int) -> Iterator[int]:
194 """Fibonacci series up to n"""
195 a, b = 0, 1
196 while a < n:
197 yield a
198 a, b = b, a + b
199
200
201 result = sum(Math.fib(42))
202 print("The answer is {}".format(result))
203
204
205 With caption
206 ~~~~~~~~~~~~
207
208 .. code-block:: json
209 :caption: Code Blocks can have captions, which also adds a link to it.
210
211 {
212 "session_name": "shorthands",
213 "windows": [
214 {
215 "panes": [
216 {
217 "shell_command": "echo 'This is an intentionally very long line because I want to make sure that we are handling scrollable code blocks correctly.'"
218 }
219 ],
220 "window_name": "long form"
221 }
222 ]
223 }
224
225 With line numbers
226 ~~~~~~~~~~~~~~~~~
227
228 .. code-block:: python
229 :linenos:
230 :emphasize-lines: 3,5
231
232 def some_function():
233 interesting = False
234 print("This line is highlighted.")
235 print("This one is not...")
236 print("...but this one is.")
237 print(
238 "This is an intentionally very long line because I want to make sure that we are handling scrollable code blocks correctly."
239 )
240
241 Without highlighting
242 ~~~~~~~~~~~~~~~~~~~~
243
244 .. code-block:: text
245
246 # Taken from https://en.wikipedia.org/wiki/Pseudocode#Example
247 algorithm ford-fulkerson is
248 input: Graph G with flow capacity c,
249 source node s,
250 sink node t
251 output: Flow f such that f is maximal from s to t
252
253 (Note that f(u,v) is the flow from node u to node v, and c(u,v) is the flow capacity from node u to node v)
254
255 for each edge (u, v) in GE do
256 f(u, v) ← 0
257 f(v, u) ← 0
258
259 while there exists a path p from s to t in the residual network Gf do
260 let cf be the flow capacity of the residual network Gf
261 cf(p) ← min{cf(u, v) | (u, v) in p}
262 for each edge (u, v) in p do
263 f(u, v) ← f(u, v) + cf(p)
264 f(v, u) ← −f(u, v)
265
266 return f