Debian Codegraph @

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