Debian Codegraph @

docs/user/rst/quickstart.rst

raw
1 .. include:: ../../header2.rst
2
3 A ReStructuredText Primer
4 =========================
5
6 :Author: Richard Jones
7 :Version: $Revision: 9923 $
8 :Copyright: This document has been placed in the public domain.
9
10 .. contents::
11
12
13 The text below contains links that look like "(quickref__)". These
14 are relative links that point to the `Quick reStructuredText`_ user
15 reference. If these links don't work, please refer to the `master
16 quick reference`_ document.
17
18 __
19 .. _Quick reStructuredText: quickref.html
20 .. _master quick reference:
21 https://docutils.sourceforge.io/docs/user/rst/quickref.html
22
23 .. Note:: This document is an informal introduction to
24 reStructuredText. The `What Next?`_ section below has links to
25 further resources, including a formal reference.
26
27
28 Structure
29 ---------
30
31 From the outset, let me say that "Structured Text" is probably a bit
32 of a misnomer. It's more like "Relaxed Text" that uses certain
33 consistent patterns. These patterns are interpreted by a HTML
34 converter to produce "Very Structured Text" that can be used by a web
35 browser.
36
37 The most basic pattern recognised is a **paragraph** (quickref__).
38 That's a chunk of text that is separated by blank lines (one is
39 enough). Paragraphs must have the same indentation -- that is, line
40 up at their left edge. Paragraphs that start indented will result in
41 indented quote paragraphs. For example::
42
43 This is a paragraph. It's quite
44 short.
45
46 This paragraph will result in an indented block of
47 text, typically used for quoting other text.
48
49 This is another one.
50
51 Results in:
52
53 This is a paragraph. It's quite
54 short.
55
56 This paragraph will result in an indented block of
57 text, typically used for quoting other text.
58
59 This is another one.
60
61 __ quickref.html#paragraphs
62
63
64 Text styles
65 -----------
66
67 (quickref__)
68
69 __ quickref.html#inline-markup
70
71 Inside paragraphs and other bodies of text, you may additionally mark
72 text for *italics* with "``*italics*``" or **bold** with
73 "``**bold**``". This is called "inline markup".
74
75 If you want something to appear as a fixed-space literal, use
76 "````double back-quotes````". Note that no further fiddling is done
77 inside the double back-quotes -- so asterisks "``*``" etc. are left
78 alone.
79
80 If you find that you want to use one of the "special" characters in
81 text, it will generally be OK -- reStructuredText is pretty smart.
82 For example, this lone asterisk * is handled just fine, as is the
83 asterisk in this equation: 5*6=30. If you actually
84 want text \*surrounded by asterisks* to **not** be italicised, then
85 you need to indicate that the asterisk is not special. You do this by
86 placing a backslash just before it, like so "``\*``" (quickref__), or
87 by enclosing it in double back-quotes (inline literals), like this::
88
89 ``*``
90
91 __ quickref.html#escaping
92
93 .. Tip:: Think of inline markup as a form of (parentheses) and use it
94 the same way: immediately before and after the text being marked
95 up. Inline markup by itself (surrounded by whitespace) or in the
96 middle of a word won't be recognized. See the `markup spec`__ for
97 full details.
98
99 __ ../../ref/rst/restructuredtext.html#inline-markup
100
101
102 Lists
103 -----
104
105 Lists of items come in three main flavours: **enumerated**,
106 **bulleted** and **definitions**. In all list cases, you may have as
107 many paragraphs, sublists, etc. as you want, as long as the left-hand
108 side of the paragraph or whatever aligns with the first line of text
109 in the list item.
110
111 Lists must always start a new paragraph -- that is, they must appear
112 after a blank line.
113
114 **enumerated** lists (numbers, letters or roman numerals; quickref__)
115 __ quickref.html#enumerated-lists
116
117 Start a line off with a number or letter followed by a period ".",
118 right bracket ")" or surrounded by brackets "( )" -- whatever you're
119 comfortable with. All of the following forms are recognised::
120
121 1. numbers
122
123 A. upper-case letters
124 and it goes over many lines
125
126 with two paragraphs and all!
127
128 a. lower-case letters
129
130 3. with a sub-list starting at a different number
131 4. make sure the numbers are in the correct sequence though!
132
133 I. upper-case roman numerals
134
135 i. lower-case roman numerals
136
137 (1) numbers again
138
139 1) and again
140
141 Results in (note: the different enumerated list styles are not
142 always supported by every web browser, so you may not get the full
143 effect here):
144
145 1. numbers
146
147 A. upper-case letters
148 and it goes over many lines
149
150 with two paragraphs and all!
151
152 a. lower-case letters
153
154 3. with a sub-list starting at a different number
155 4. make sure the numbers are in the correct sequence though!
156
157 I. upper-case roman numerals
158
159 i. lower-case roman numerals
160
161 (1) numbers again
162
163 1) and again
164
165 **bulleted** lists (quickref__)
166 __ quickref.html#bullet-lists
167
168 Just like enumerated lists, start the line off with a bullet point
169 character - either "-", "+" or "*"::
170
171 * a bullet point using "*"
172
173 - a sub-list using "-"
174
175 + yet another sub-list
176
177 - another item
178
179 Results in:
180
181 * a bullet point using "*"
182
183 - a sub-list using "-"
184
185 + yet another sub-list
186
187 - another item
188
189 **definition** lists (quickref__)
190 __ quickref.html#definition-lists
191
192 Unlike the other two, the definition lists consist of a term, and
193 the definition of that term. The format of a definition list is::
194
195 what
196 Definition lists associate a term with a definition.
197
198 *how*
199 The term is a one-line phrase, and the definition is one or more
200 paragraphs or body elements, indented relative to the term.
201 Blank lines are not allowed between term and definition.
202
203 Results in:
204
205 what
206 Definition lists associate a term with a definition.
207
208 *how*
209 The term is a one-line phrase, and the definition is one or more
210 paragraphs or body elements, indented relative to the term.
211 Blank lines are not allowed between term and definition.
212
213
214 Preformatting (code samples)
215 ----------------------------
216 (quickref__)
217
218 __ quickref.html#literal-blocks
219
220 To just include a chunk of preformatted, never-to-be-fiddled-with
221 text, finish the prior paragraph with "``::``". The preformatted
222 block is finished when the text falls back to the same indentation
223 level as a paragraph prior to the preformatted block. For example::
224
225 An example::
226
227 Whitespace, newlines, blank lines, and all kinds of markup
228 (like *this* or \this) is preserved by literal blocks.
229 Lookie here, I've dropped an indentation level
230 (but not far enough)
231
232 no more example
233
234 Results in:
235
236 An example::
237
238 Whitespace, newlines, blank lines, and all kinds of markup
239 (like *this* or \this) is preserved by literal blocks.
240 Lookie here, I've dropped an indentation level
241 (but not far enough)
242
243 no more example
244
245 Note that if a paragraph consists only of "``::``", then it's removed
246 from the output::
247
248 ::
249
250 This is preformatted text, and the
251 last "::" paragraph is removed
252
253 Results in:
254
255 ::
256
257 This is preformatted text, and the
258 last "::" paragraph is removed
259
260
261 Sections
262 --------
263
264 (quickref__)
265
266 __ quickref.html#section-structure
267
268 To break longer text up into sections, you use **section headers**.
269 These are a single line of text (one or more words) with adornment: an
270 underline alone, or an underline and an overline together, in dashes
271 "``-----``", equals "``======``", tildes "``~~~~~~``" or any of the
272 non-alphanumeric characters ``= - ` : ' " ~ ^ _ * + # < >`` that you
273 feel comfortable with. An underline-only adornment is distinct from
274 an overline-and-underline adornment using the same character. The
275 underline/overline must be at least as long as the title text. Be
276 consistent, since all sections marked with the same adornment style
277 are deemed to be at the same level::
278
279 Chapter 1 Title
280 ===============
281
282 Section 1.1 Title
283 -----------------
284
285 Subsection 1.1.1 Title
286 ~~~~~~~~~~~~~~~~~~~~~~
287
288 Section 1.2 Title
289 -----------------
290
291 Chapter 2 Title
292 ===============
293
294 This results in the following structure, illustrated by simplified
295 pseudo-XML::
296
297 <section>
298 <title>
299 Chapter 1 Title
300 <section>
301 <title>
302 Section 1.1 Title
303 <section>
304 <title>
305 Subsection 1.1.1 Title
306 <section>
307 <title>
308 Section 1.2 Title
309 <section>
310 <title>
311 Chapter 2 Title
312
313 (Pseudo-XML uses indentation for nesting and has no end-tags. It's
314 not possible to show actual processed output, as in the other
315 examples, because sections cannot exist inside block quotes. For a
316 concrete example, compare the section structure of this document's
317 source text and processed output.)
318
319 Note that section headers are available as link targets, just using
320 their name. To link to the Lists_ heading, I write "``Lists_``". If
321 the heading has a space in it like `text styles`_, we need to quote
322 the heading "```text styles`_``".
323
324
325 Document Title / Subtitle
326 `````````````````````````
327
328 The title of the whole document is distinct from section titles and
329 may be formatted somewhat differently (e.g. the HTML writer by default
330 shows it as a centered heading).
331
332 To indicate the document title in reStructuredText, use a section title
333 with unique adornment style at the beginning of the document.
334 To indicate the document subtitle, use another unique adornment style
335 immediately after the document title. For example::
336
337 ================
338 Document Title
339 ================
340 ----------
341 Subtitle
342 ----------
343
344 Section Title
345 =============
346
347 ...
348
349 Note that "Document Title" and "Section Title" above both use equals
350 signs, but are distict and unrelated styles. The text of
351 overline-and-underlined titles (but not underlined-only) may be inset
352 for aesthetics.
353
354 Counterexample::
355
356 Here's an ordinary paragraph.
357
358 This is *not* a Document Title
359 ==============================
360
361 The "ordinary paragraph" above the section title
362 prevents it from becoming the document title.
363
364 Another counterexample::
365
366 This is not the Document Title, because...
367 ===========================================
368
369 Here's an ordinary paragraph.
370
371 ... the title adornment is not unique
372 =====================================
373
374 Another ordinary paragraph.
375
376
377 Images
378 ------
379
380 (quickref__)
381
382 __ quickref.html#directives
383
384 To include an image in your document, you use the the ``image`` directive__.
385 For example::
386
387 .. image:: images/biohazard.png
388
389 results in:
390
391 .. image:: images/biohazard.png
392
393 The ``images/biohazard.png`` part indicates the filename of the image
394 you wish to appear in the document. There's no restriction placed on
395 the image (format, size etc). If the image is to appear in HTML and
396 you wish to supply additional information, you may::
397
398 .. image:: images/biohazard.png
399 :height: 100
400 :width: 200
401 :scale: 50
402 :alt: alternate text
403
404 See the full `image directive documentation`__ for more info.
405
406 __ ../../ref/rst/directives.html
407 __ ../../ref/rst/directives.html#images
408
409
410 What Next?
411 ----------
412
413 This primer introduces the most common features of reStructuredText,
414 but there are a lot more to explore. The `Quick reStructuredText`_
415 user reference is a good place to go next. For complete details, the
416 `reStructuredText Markup Specification`_ is the place to go [#]_.
417
418 Users who have questions or need assistance with Docutils or
419 reStructuredText should post a message to the Docutils-users_ mailing
420 list.
421
422 .. [#] If that relative link doesn't work, try the master document:
423 https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html.
424
425 .. _reStructuredText Markup Specification:
426 ../../ref/rst/restructuredtext.html
427 .. _Docutils-users: ../mailing-lists.html#docutils-users
428 .. _Docutils project web site: https://docutils.sourceforge.io/