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