Debian Codegraph @

docs/dev/rst/problems.rst

raw
1 .. include:: ../../header2.rst
2
3 ==============================
4 Problems With StructuredText
5 ==============================
6 :Author: David Goodger
7 :Contact: [email protected]
8 :Revision: $Revision: 9906 $
9 :Date: $Date: 2024-08-15 10:43:38 +0200 (Do, 15. Aug 2024) $
10 :Copyright: This document has been placed in the public domain.
11
12 There are several problems, unresolved issues, and areas of
13 controversy within StructuredText_ (Classic and Next Generation). In
14 order to resolve all these issues, this analysis brings all of the
15 issues out into the open, enumerates all the alternatives, and
16 proposes solutions to be incorporated into the reStructuredText_
17 specification.
18
19
20 .. contents::
21
22
23 Formal Specification
24 ====================
25
26 The description in the original StructuredText.py has been criticized
27 for being vague. For practical purposes, "the code *is* the spec."
28 Tony Ibbs has been working on deducing a `detailed description`_ from
29 the documentation and code of StructuredTextNG_. Edward Loper's
30 STMinus_ is another attempt to formalize a spec.
31
32 For this kind of a project, the specification should always precede
33 the code. Otherwise, the markup is a moving target which can never be
34 adopted as a standard. Of course, a specification may be revised
35 during lifetime of the code, but without a spec there is no visible
36 control and thus no confidence.
37
38
39 Understanding and Extending the Code
40 ====================================
41
42 The original StructuredText_ is a dense mass of sparsely commented
43 code and inscrutable regular expressions. It was not designed to be
44 extended and is very difficult to understand. StructuredTextNG_ has
45 been designed to allow input (syntax) and output extensions, but its
46 documentation (both internal [comments & docstrings], and external) is
47 inadequate for the complexity of the code itself.
48
49 For reStructuredText to become truly useful, perhaps even part of
50 Python's standard library, it must have clear, understandable
51 documentation and implementation code. For the implementation of
52 reStructuredText to be taken seriously, it must be a sterling example
53 of the potential of docstrings; the implementation must practice what
54 the specification preaches.
55
56
57 Section Structure via Indentation
58 =================================
59
60 Setext_ required that body text be indented by 2 spaces. The original
61 StructuredText_ and StructuredTextNG_ require that section structure
62 be indicated through indentation, as "inspired by Python". For
63 certain structures with a very limited, local extent (such as lists,
64 block quotes, and literal blocks), indentation naturally indicates
65 structure or hierarchy. For sections (which may have a very large
66 extent), structure via indentation is unnecessary, unnatural and
67 ambiguous. Rather, the syntax of the section title *itself* should
68 indicate that it is a section title.
69
70 The original StructuredText states that "A single-line paragraph whose
71 immediately succeeding paragraphs are lower level is treated as a
72 header." Requiring indentation in this way is:
73
74 - Unnecessary. The vast majority of docstrings and standalone
75 documents will have no more than one level of section structure.
76 Requiring indentation for such docstrings is unnecessary and
77 irritating.
78
79 - Unnatural. Most published works use title style (type size, face,
80 weight, and position) and/or section/subsection numbering rather
81 than indentation to indicate hierarchy. This is a tradition with a
82 very long history.
83
84 - Ambiguous. A StructuredText header is indistinguishable from a
85 one-line paragraph followed by a block quote (precluding the use of
86 block quotes). Enumerated section titles are ambiguous (is it a
87 header? is it a list item?). Some additional adornment must be
88 required to confirm the line's role as a title, both to a parser and
89 to the human reader of the source text.
90
91 Python's use of significant whitespace is a wonderful (if not
92 original) innovation, however requiring indentation in ordinary
93 written text is hypergeneralization.
94
95 reStructuredText_ indicates section structure through title adornment
96 style (as exemplified by this document). This is far more natural.
97 In fact, it is already in widespread use in plain text documents,
98 including in Python's standard distribution (such as the toplevel
99 README_ file).
100
101
102 Character Escaping Mechanism
103 ============================
104
105 No matter what characters are chosen for markup, some day someone will
106 want to write documentation *about* that markup or using markup
107 characters in a non-markup context. Therefore, any complete markup
108 language must have an escaping or encoding mechanism. For a
109 lightweight markup system, encoding mechanisms like SGML/XML's '*'
110 are out. So an escaping mechanism is in. However, with carefully
111 chosen markup, it should be necessary to use the escaping mechanism
112 only infrequently.
113
114 reStructuredText_ needs an escaping mechanism: a way to treat
115 markup-significant characters as the characters themselves. Currently
116 there is no such mechanism (although ZWiki uses '!'). What are the
117 candidates?
118
119 1. ``!``
120 (http://www.zope.org/DevHome/Members/jim/StructuredTextWiki/NGEscaping)
121 2. ``\``
122 3. ``~``
123 4. doubling of characters
124
125 The best choice for this is the backslash (``\``). It's "the single
126 most popular escaping character in the world!", therefore familiar and
127 unsurprising. Since characters only need to be escaped under special
128 circumstances, which are typically those explaining technical
129 programming issues, the use of the backslash is natural and
130 understandable. Python docstrings can be raw (prefixed with an 'r',
131 as in 'r""'), which would obviate the need for gratuitous doubling-up
132 of backslashes.
133
134 (On 2001-03-29 on the Doc-SIG mailing list, GvR endorsed backslash
135 escapes, saying, "'nuff said. Backslash it is." Although neither
136 legally binding nor irrevocable nor any kind of guarantee of anything,
137 it is a good sign.)
138
139 The rule would be: An unescaped backslash followed by any markup
140 character escapes the character. The escaped character represents the
141 character itself, and is prevented from playing a role in any markup
142 interpretation. The backslash is removed from the output. A literal
143 backslash is represented by an "escaped backslash," two backslashes in
144 a row.
145
146 A carefully constructed set of recognition rules for inline markup
147 will obviate the need for backslash-escapes in almost all cases; see
148 `Delimitation of Inline Markup`_ below.
149
150 When an expression (requiring backslashes and other characters used
151 for markup) becomes too complicated and therefore unreadable, a
152 literal block may be used instead. Inside literal blocks, no markup
153 is recognized, therefore backslashes (for the purpose of escaping
154 markup) become unnecessary.
155
156 We could allow backslashes preceding non-markup characters to remain
157 in the output. This would make describing regular expressions and
158 other uses of backslashes easier. However, this would complicate the
159 markup rules and would be confusing.
160
161
162 Blank Lines in Lists
163 ====================
164
165 Oft-requested in Doc-SIG (the earliest reference is dated 1996-08-13)
166 is the ability to write lists without requiring blank lines between
167 items. In docstrings, space is at a premium. Authors want to convey
168 their API or usage information in as compact a form as possible.
169 StructuredText_ requires blank lines between all body elements,
170 including list items, even when boundaries are obvious from the markup
171 itself.
172
173 In reStructuredText, blank lines are optional between list items.
174 However, in order to eliminate ambiguity, a blank line is required
175 before the first list item and after the last. Nested lists also
176 require blank lines before the list start and after the list end.
177
178
179 Bullet List Markup
180 ==================
181
182 StructuredText_ includes 'o' as a bullet character. This is dangerous
183 and counter to the language-independent nature of the markup. There
184 are many languages in which 'o' is a word. For example, in Spanish::
185
186 Llamame a la casa
187 o al trabajo.
188
189 (Call me at home or at work.)
190
191 And in Japanese (when romanized)::
192
193 Senshuu no doyoubi ni tegami
194 o kakimashita.
195
196 ([I] wrote a letter on Saturday last week.)
197
198 If a paragraph containing an 'o' word wraps such that the 'o' is the
199 first text on a line, or if a paragraph begins with such a word, it
200 could be misinterpreted as a bullet list.
201
202 In reStructuredText_, 'o' is not used as a bullet character. '-',
203 '*', and '+' are the possible bullet characters.
204
205
206 Enumerated List Markup
207 ======================
208
209 StructuredText enumerated lists are allowed to begin with numbers and
210 letters followed by a period or right-parenthesis, then whitespace.
211 This has surprising consequences for writing styles. For example,
212 this is recognized as an enumerated list item by StructuredText::
213
214 Mr. Creosote.
215
216 People will write enumerated lists in all different ways. It is folly
217 to try to come up with the "perfect" format for an enumerated list,
218 and limit the docstring parser's recognition to that one format only.
219
220 Rather, the parser should recognize a variety of enumerator styles.
221 It is also recommended that the enumerator of the first list item be
222 ordinal-1 ('1', 'A', 'a', 'I', or 'i'), as output formats may not be
223 able to begin a list at an arbitrary enumeration.
224
225 An initial idea was to require two or more consistent enumerated list
226 items in a row. This idea proved impractical and was dropped. In
227 practice, the presence of a proper enumerator is enough to reliably
228 recognize an enumerated list item; any ambiguities are reported by the
229 parser. Here's the original idea for posterity:
230
231 The parser should recognize a variety of enumerator styles, mark
232 each block as a potential enumerated list item (PELI), and
233 interpret the enumerators of adjacent PELIs to decide whether they
234 make up a consistent enumerated list.
235
236 If a PELI is labeled with a "1.", and is immediately followed by a
237 PELI labeled with a "2.", we've got an enumerated list. Or "(A)"
238 followed by "(B)". Or "i)" followed by "ii)", etc. The chances
239 of accidentally recognizing two adjacent and consistently labeled
240 PELIs, are acceptably small.
241
242 For an enumerated list to be recognized, the following must be
243 true:
244
245 - the list must consist of multiple adjacent list items (2 or
246 more)
247 - the enumerators must all have the same format
248 - the enumerators must be sequential
249
250
251 Definition List Markup
252 ======================
253
254 StructuredText uses ' -- ' (whitespace, two hyphens, whitespace) on
255 the first line of a paragraph to indicate a definition list item. The
256 ' -- ' serves to separate the term (on the left) from the definition
257 (on the right).
258
259 Many people use ' -- ' as an em-dash in their text, conflicting with
260 the StructuredText usage. Although the Chicago Manual of Style says
261 that spaces should not be used around an em-dash, Peter Funk pointed
262 out that this is standard usage in German (according to the Duden, the
263 official German reference), and possibly in other languages as well.
264 The widespread use of ' -- ' precludes its use for definition lists;
265 it would violate the "unsurprising" criterion.
266
267 A simpler, and at least equally visually distinctive construct
268 (proposed by Guido van Rossum, who incidentally is a frequent user of
269 ' -- ') would do just as well::
270
271 term 1
272 Definition.
273
274 term 2
275 Definition 2, paragraph 1.
276
277 Definition 2, paragraph 2.
278
279 A reStructuredText definition list item consists of a term and a
280 definition. A term is a simple one-line paragraph. A definition is a
281 block indented relative to the term, and may contain multiple
282 paragraphs and other body elements. No blank line precedes a
283 definition (this distinguishes definition lists from block quotes).
284
285
286 Literal Blocks
287 ==============
288
289 The StructuredText_ specification has literal blocks indicated by
290 'example', 'examples', or '::' ending the preceding paragraph. STNG
291 only recognizes '::'; 'example'/'examples' are not implemented. This
292 is good; it fixes an unnecessary language dependency. The problem is
293 what to do with the sometimes- unwanted '::'.
294
295 In reStructuredText_ '::' at the end of a paragraph indicates that
296 subsequent *indented* blocks are treated as literal text. No further
297 markup interpretation is done within literal blocks (not even
298 backslash-escapes). If the '::' is preceded by whitespace, '::' is
299 omitted from the output; if '::' was the sole content of a paragraph,
300 the entire paragraph is removed (no 'empty' paragraph remains). If
301 '::' is preceded by a non-whitespace character, '::' is replaced by
302 ':' (i.e., the extra colon is removed).
303
304 Thus, a section could begin with a literal block as follows::
305
306 Section Title
307 -------------
308
309 ::
310
311 print "this is example literal"
312
313
314 Tables
315 ======
316
317 The table markup scheme in classic StructuredText was horrible. Its
318 omission from StructuredTextNG is welcome, and its markup will not be
319 repeated here. However, tables themselves are useful in
320 documentation. Alternatives:
321
322 1. This format is the most natural and obvious. It was independently
323 invented (no great feat of creation!), and later found to be the
324 format supported by the `Emacs table mode`_::
325
326 +------------+------------+------------+--------------+
327 | Header 1 | Header 2 | Header 3 | Header 4 |
328 +============+============+============+==============+
329 | Column 1 | Column 2 | Column 3 & 4 span (Row 1) |
330 +------------+------------+------------+--------------+
331 | Column 1 & 2 span | Column 3 | - Column 4 |
332 +------------+------------+------------+ - Row 2 & 3 |
333 | 1 | 2 | 3 | - span |
334 +------------+------------+------------+--------------+
335
336 Tables are described with a visual outline made up of the
337 characters '-', '=', '|', and '+':
338
339 - The hyphen ('-') is used for horizontal lines (row separators).
340 - The equals sign ('=') is optionally used as a header separator
341 (as of version 1.5.24, this is not supported by the Emacs table
342 mode).
343 - The vertical bar ('|') is used for for vertical lines (column
344 separators).
345 - The plus sign ('+') is used for intersections of horizontal and
346 vertical lines.
347
348 Row and column spans are possible simply by omitting the column or
349 row separators, respectively. The header row separator must be
350 complete; in other words, a header cell may not span into the table
351 body. Each cell contains body elements, and may have multiple
352 paragraphs, lists, etc. Initial spaces for a left margin are
353 allowed; the first line of text in a cell determines its left
354 margin.
355
356 2. Below is a simpler table structure. It may be better suited to
357 manual input than alternative #1, but there is no Emacs editing
358 mode available. One disadvantage is that it resembles section
359 titles; a one-column table would look exactly like section &
360 subsection titles. ::
361
362 ============ ============ ============ ==============
363 Header 1 Header 2 Header 3 Header 4
364 ============ ============ ============ ==============
365 Column 1 Column 2 Column 3 & 4 span (Row 1)
366 ------------ ------------ ---------------------------
367 Column 1 & 2 span Column 3 - Column 4
368 ------------------------- ------------ - Row 2 & 3
369 1 2 3 - span
370 ============ ============ ============ ==============
371
372 The table begins with a top border of equals signs with a space at
373 each column boundary (regardless of spans). Each row is
374 underlined. Internal row separators are underlines of '-', with
375 spaces at column boundaries. The last of the optional head rows is
376 underlined with '=', again with spaces at column boundaries.
377 Column spans have no spaces in their underline. Row spans simply
378 lack an underline at the row boundary. The bottom boundary of the
379 table consists of '=' underlines. A blank line is required
380 following a table.
381
382 3. A minimalist alternative is as follows::
383
384 ==== ===== ======== ======== ======= ==== ===== =====
385 Old State Input Action New State Notes
386 ----------- -------- ----------------- -----------
387 ids types new type sys.msg. dupname ids types
388 ==== ===== ======== ======== ======= ==== ===== =====
389 -- -- explicit -- -- new True
390 -- -- implicit -- -- new False
391 None False explicit -- -- new True
392 old False explicit implicit old new True
393 None True explicit explicit new None True
394 old True explicit explicit new,old None True [1]
395 None False implicit implicit new None False
396 old False implicit implicit new,old None False
397 None True implicit implicit new None True
398 old True implicit implicit new old True
399 ==== ===== ======== ======== ======= ==== ===== =====
400
401 The table begins with a top border of equals signs with one or more
402 spaces at each column boundary (regardless of spans). There must
403 be at least two columns in the table (to differentiate it from
404 section headers). Each line starts a new row. The rightmost
405 column is unbounded; text may continue past the edge of the table.
406 Each row/line must contain spaces at column boundaries, except for
407 explicit column spans. Underlines of '-' can be used to indicate
408 column spans, but should be used sparingly if at all. Lines
409 containing column span underlines may not contain any other text.
410 The last of the optional head rows is underlined with '=', again
411 with spaces at column boundaries. The bottom boundary of the table
412 consists of '=' underlines. A blank line is required following a
413 table.
414
415 This table sums up the features. Using all the features in such a
416 small space is not pretty though::
417
418 ======== ======== ========
419 Header 2 & 3 Span
420 ------------------
421 Header 1 Header 2 Header 3
422 ======== ======== ========
423 Each line is a new row.
424 Each row consists of one line only.
425 Row spans are not possible.
426 The last column may spill over to the right.
427 Column spans are possible with an underline joining columns.
428 ----------------------------
429 The span is limited to the row above the underline.
430 ======== ======== ========
431
432 4. As a variation of alternative 3, bullet list syntax in the first
433 column could be used to indicate row starts. Multi-line rows are
434 possible, but row spans are not. For example::
435
436 ===== =====
437 col 1 col 2
438 ===== =====
439 - 1 Second column of row 1.
440 - 2 Second column of row 2.
441 Second line of paragraph.
442 - 3 Second column of row 3.
443
444 Second paragraph of row 3,
445 column 2
446 ===== =====
447
448 Column spans would be indicated on the line after the last line of
449 the row. To indicate a real bullet list within a first-column
450 cell, simply nest the bullets.
451
452 5. In a further variation, we could simply assume that whitespace in
453 the first column implies a multi-line row; the text in other
454 columns is continuation text. For example::
455
456 ===== =====
457 col 1 col 2
458 ===== =====
459 1 Second column of row 1.
460 2 Second column of row 2.
461 Second line of paragraph.
462 3 Second column of row 3.
463
464 Second paragraph of row 3,
465 column 2
466 ===== =====
467
468 Limitations of this approach:
469
470 - Cells in the first column are limited to one line of text.
471
472 - Cells in the first column *must* contain some text; blank cells
473 would lead to a misinterpretation. An empty comment ("..") is
474 sufficient.
475
476 6. Combining alternative 3 and 4, a bullet list in the first column
477 could mean multi-line rows, and no bullet list means single-line
478 rows only.
479
480 Alternatives 1 and 5 has been adopted by reStructuredText.
481
482
483 Delimitation of Inline Markup
484 =============================
485
486 StructuredText specifies that inline markup must begin with
487 whitespace, precluding such constructs as parenthesized or quoted
488 emphatic text::
489
490 "**What?**" she cried. (*exit stage left*)
491
492 The `reStructuredText markup specification`_ allows for such
493 constructs and disambiguates inline markup through a set of
494 recognition rules. These recognition rules define the context of
495 markup start-strings and end-strings, allowing markup characters to be
496 used in most non-markup contexts without a problem (or a backslash).
497 So we can say, "Use asterisks (*) around words or phrases to
498 *emphasisze* them." The '(*)' will not be recognized as markup. This
499 reduces the need for markup escaping to the point where an escape
500 character is *almost* (but not quite!) unnecessary.
501
502
503 Underlining
504 ===========
505
506 StructuredText uses '_text_' to indicate underlining. To quote David
507 Ascher in his 2000-01-21 Doc-SIG mailing list post, "Docstring
508 grammar: a very revised proposal":
509
510 The tagging of underlined text with _'s is suboptimal. Underlines
511 shouldn't be used from a typographic perspective (underlines were
512 designed to be used in manuscripts to communicate to the
513 typesetter that the text should be italicized -- no well-typeset
514 book ever uses underlines), and conflict with double-underscored
515 Python variable names (__init__ and the like), which would get
516 truncated and underlined when that effect is not desired. Note
517 that while *complete* markup would prevent that truncation
518 ('__init__'), I think of docstring markups much like I think of
519 type annotations -- they should be optional and above all do no
520 harm. In this case the underline markup does harm.
521
522 Underlining is not part of the reStructuredText specification.
523
524
525 Inline Literals
526 ===============
527
528 StructuredText's markup for inline literals (text left as-is,
529 verbatim, usually in a monospaced font; as in HTML <TT>) is single
530 quotes ('literals'). The problem with single quotes is that they are
531 too often used for other purposes:
532
533 - Apostrophes: "Don't blame me, 'cause it ain't mine, it's Chris'.";
534
535 - Quoting text:
536
537 First Bruce: "Well Bruce, I heard the prime minister use it.
538 'S'hot enough to boil a monkey's bum in 'ere your Majesty,' he
539 said, and she smiled quietly to herself."
540
541 In the UK, single quotes are used for dialogue in published works.
542
543 - String literals: s = ''
544
545 Alternatives::
546
547 'text' \'text\' ''text'' "text" \"text\" ""text""
548 #text# @text@ `text` ^text^ ``text'' ``text``
549
550 The examples below contain inline literals, quoted text, and
551 apostrophes. Each example should evaluate to the following HTML::
552
553 Some <TT>code</TT>, with a 'quote', "double", ain't it grand?
554 Does <TT>a[b] = 'c' + "d" + `2^3`</TT> work?
555
556 0. Some code, with a quote, double, ain't it grand?
557 Does a[b] = 'c' + "d" + `2^3` work?
558 1. Some 'code', with a \'quote\', "double", ain\'t it grand?
559 Does 'a[b] = \'c\' + "d" + `2^3`' work?
560 2. Some \'code\', with a 'quote', "double", ain't it grand?
561 Does \'a[b] = 'c' + "d" + `2^3`\' work?
562 3. Some ''code'', with a 'quote', "double", ain't it grand?
563 Does ''a[b] = 'c' + "d" + `2^3`'' work?
564 4. Some "code", with a 'quote', \"double\", ain't it grand?
565 Does "a[b] = 'c' + "d" + `2^3`" work?
566 5. Some \"code\", with a 'quote', "double", ain't it grand?
567 Does \"a[b] = 'c' + "d" + `2^3`\" work?
568 6. Some ""code"", with a 'quote', "double", ain't it grand?
569 Does ""a[b] = 'c' + "d" + `2^3`"" work?
570 7. Some #code#, with a 'quote', "double", ain't it grand?
571 Does #a[b] = 'c' + "d" + `2^3`# work?
572 8. Some @code@, with a 'quote', "double", ain't it grand?
573 Does @a[b] = 'c' + "d" + `2^3`@ work?
574 9. Some `code`, with a 'quote', "double", ain't it grand?
575 Does `a[b] = 'c' + "d" + \`2^3\`` work?
576 10. Some ^code^, with a 'quote', "double", ain't it grand?
577 Does ^a[b] = 'c' + "d" + `2\^3`^ work?
578 11. Some ``code'', with a 'quote', "double", ain't it grand?
579 Does ``a[b] = 'c' + "d" + `2^3`'' work?
580 12. Some ``code``, with a 'quote', "double", ain't it grand?
581 Does ``a[b] = 'c' + "d" + `2^3\``` work?
582
583 Backquotes (#9 & #12) are the best choice. They are unobtrusive and
584 relatviely rarely used (more rarely than ' or ", anyhow). Backquotes
585 have the connotation of 'quotes', which other options (like carets,
586 #10) don't.
587
588 Analogously with ``*emph*`` & ``**strong**``, double-backquotes (#12)
589 could be used for inline literals. If single-backquotes are used for
590 'interpreted text' (context-sensitive domain-specific descriptive
591 markup) such as function name hyperlinks in Python docstrings, then
592 double-backquotes could be used for absolute-literals, wherein no
593 processing whatsoever takes place. An advantage of double-backquotes
594 would be that backslash-escaping would no longer be necessary for
595 embedded single-backquotes; however, embedded double-backquotes (in an
596 end-string context) would be illegal. See `Backquotes in
597 Phrase-Links`__ in `Record of reStructuredText Syntax Alternatives`__.
598
599 __ alternatives.html#backquotes-in-phrase-links
600 __ alternatives.html
601
602 Alternative choices are carets (#10) and TeX-style quotes (#11). For
603 examples of TeX-style quoting, see
604 http://www.zope.org/Members/jim/StructuredTextWiki/CustomizingTheDocumentProcessor.
605
606 Some existing uses of backquotes:
607
608 1. As a synonym for repr() in Python.
609 2. For command-interpolation in shell scripts.
610 3. Used as open-quotes in TeX code (and carried over into plaintext
611 by TeXies).
612
613 The inline markup start-string and end-string recognition rules
614 defined by the `reStructuredText markup specification`_ would allow
615 all of these cases inside inline literals, with very few exceptions.
616 As a fallback, literal blocks could handle all cases.
617
618 Outside of inline literals, the above uses of backquotes would require
619 backslash-escaping. However, these are all prime examples of text
620 that should be marked up with inline literals.
621
622 If either backquotes or straight single-quotes are used as markup,
623 TeX-quotes are too troublesome to support, so no special-casing of
624 TeX-quotes should be done (at least at first). If TeX-quotes have to
625 be used outside of literals, a single backslash-escaped would suffice:
626 \``TeX quote''. Ugly, true, but very infrequently used.
627
628 Using literal blocks is a fallback option which removes the need for
629 backslash-escaping::
630
631 like this::
632
633 Here, we can do ``absolutely'' anything `'`'\|/|\ we like!
634
635 No mechanism for inline literals is perfect, just as no escaping
636 mechanism is perfect. No matter what we use, complicated inline
637 expressions involving the inline literal quote and/or the backslash
638 will end up looking ugly. We can only choose the least often ugly
639 option.
640
641 reStructuredText will use double backquotes for inline literals, and
642 single backqoutes for interpreted text.
643
644
645 Hyperlinks
646 ==========
647
648 There are three forms of hyperlink currently in StructuredText_:
649
650 1. (Absolute & relative URIs.) Text enclosed by double quotes
651 followed by a colon, a URI, and concluded by punctuation plus white
652 space, or just white space, is treated as a hyperlink::
653
654 "Python":http://www.python.org/
655
656 2. (Absolute URIs only.) Text enclosed by double quotes followed by a
657 comma, one or more spaces, an absolute URI and concluded by
658 punctuation plus white space, or just white space, is treated as a
659 hyperlink::
660
661 "mail me", mailto:[email protected]
662
663 3. (Endnotes.) Text enclosed by brackets link to an endnote at the
664 end of the document: at the beginning of the line, two dots, a
665 space, and the same text in brackets, followed by the end note
666 itself::
667
668 Please refer to the fine manual [GVR2001].
669
670 .. [GVR2001] Python Documentation, Release 2.1, van Rossum,
671 Drake, et al., http://www.python.org/doc/
672
673 The problem with forms 1 and 2 is that they are neither intuitive nor
674 unobtrusive (they break design goals 5 & 2). They overload
675 double-quotes, which are too often used in ordinary text (potentially
676 breaking design goal 4). The brackets in form 3 are also too common
677 in ordinary text (such as [nested] asides and Python lists like [12]).
678
679 Alternatives:
680
681 1. Have no special markup for hyperlinks.
682
683 2. A. Interpret and mark up hyperlinks as any contiguous text
684 containing '://' or ':...@' (absolute URI) or '@' (email
685 address) after an alphanumeric word. To de-emphasize the URI,
686 simply enclose it in parentheses:
687
688 Python (http://www.python.org/)
689
690 B. Leave special hyperlink markup as a domain-specific extension.
691 Hyperlinks in ordinary reStructuredText documents would be
692 required to be standalone (i.e. the URI text inline in the
693 document text). Processed hyperlinks (where the URI text is
694 hidden behind the link) are important enough to warrant syntax.
695
696 3. The original Setext_ introduced a mechanism of indirect hyperlinks.
697 A source link word ('hot word') in the text was given a trailing
698 underscore::
699
700 Here is some text with a hyperlink_ built in.
701
702 The hyperlink itself appeared at the end of the document on a line
703 by itself, beginning with two dots, a space, the link word with a
704 leading underscore, whitespace, and the URI itself::
705
706 .. _hyperlink http://www.123.xyz
707
708 Setext used ``underscores_instead_of_spaces_`` for phrase links.
709
710 With some modification, alternative 3 best satisfies the design goals.
711 It has the advantage of being readable and relatively unobtrusive.
712 Since each source link must match up to a target, the odd variable
713 ending in an underscore can be spared being marked up (although it
714 should generate a "no such link target" warning). The only
715 disadvantage is that phrase-links aren't possible without some
716 obtrusive syntax.
717
718 We could achieve phrase-links if we enclose the link text:
719
720 1. in double quotes::
721
722 "like this"_
723
724 2. in brackets::
725
726 [like this]_
727
728 3. or in backquotes::
729
730 `like this`_
731
732 Each gives us somewhat obtrusive markup, but that is unavoidable. The
733 bracketed syntax (#2) is reminiscent of links on many web pages
734 (intuitive), although it is somewhat obtrusive. Alternative #3 is
735 much less obtrusive, and is consistent with interpreted text: the
736 trailing underscore indicates the interpretation of the phrase, as a
737 hyperlink. #3 also disambiguates hyperlinks from footnote references.
738 Alternative #3 wins.
739
740 The same trailing underscore markup can also be used for footnote and
741 citation references, removing the problem with ordinary bracketed text
742 and Python lists::
743
744 Please refer to the fine manual [GVR2000]_.
745
746 .. [GVR2000] Python Documentation, van Rossum, Drake, et al.,
747 http://www.python.org/doc/
748
749 The two-dots-and-a-space syntax was generalized by Setext for
750 comments, which are removed from the (visible) processed output.
751 reStructuredText uses this syntax for comments, footnotes, and link
752 target, collectively termed "explicit markup". For link targets, in
753 order to eliminate ambiguity with comments and footnotes,
754 reStructuredText specifies that a colon always follow the link target
755 word/phrase. The colon denotes 'maps to'. There is no reason to
756 restrict target links to the end of the document; they could just as
757 easily be interspersed.
758
759 Internal hyperlinks (links from one point to another within a single
760 document) can be expressed by a source link as before, and a target
761 link with a colon but no URI. In effect, these targets 'map to' the
762 element immediately following.
763
764 As an added bonus, we now have a perfect candidate for
765 reStructuredText directives, a simple extension mechanism: explicit
766 markup containing a single word followed by two colons and whitespace.
767 The interpretation of subsequent data on the directive line or
768 following is directive-dependent.
769
770 To summarize::
771
772 .. This is a comment.
773
774 .. The line below is an example of a directive.
775 .. version:: 1
776
777 This is a footnote [1]_.
778
779 This internal hyperlink will take us to the footnotes_ area below.
780
781 Here is a one-word_ external hyperlink.
782
783 Here is `a hyperlink phrase`_.
784
785 .. _footnotes:
786 .. [1] Footnote text goes here.
787
788 .. external hyperlink target mappings:
789 .. _one-word: http://www.123.xyz
790 .. _a hyperlink phrase: http://www.123.xyz
791
792 The presence or absence of a colon after the target link
793 differentiates an indirect hyperlink from a footnote, respectively. A
794 footnote requires brackets. Backquotes around a target link word or
795 phrase are required if the phrase contains a colon, optional
796 otherwise.
797
798 Below are examples using no markup, the two StructuredText hypertext
799 styles, and the reStructuredText hypertext style. Each example
800 contains an indirect link, a direct link, a footnote/endnote, and
801 bracketed text. In HTML, each example should evaluate to::
802
803 <P>A <A HREF="http://spam.org">URI</A>, see <A HREF="#eggs2000">
804 [eggs2000]</A> (in Bacon [Publisher]). Also see
805 <A HREF="http://eggs.org">http://eggs.org</A>.</P>
806
807 <P><A NAME="eggs2000">[eggs2000]</A> "Spam, Spam, Spam, Eggs,
808 Bacon, and Spam"</P>
809
810 1. No markup::
811
812 A URI http://spam.org, see eggs2000 (in Bacon [Publisher]).
813 Also see http://eggs.org.
814
815 eggs2000 "Spam, Spam, Spam, Eggs, Bacon, and Spam"
816
817 2. StructuredText absolute/relative URI syntax
818 ("text":http://www.url.org)::
819
820 A "URI":http://spam.org, see [eggs2000] (in Bacon [Publisher]).
821 Also see "http://eggs.org":http://eggs.org.
822
823 .. [eggs2000] "Spam, Spam, Spam, Eggs, Bacon, and Spam"
824
825 Note that StructuredText does not recognize standalone URIs,
826 forcing doubling up as shown in the second line of the example
827 above.
828
829 3. StructuredText absolute-only URI syntax
830 ("text", mailto:[email protected])::
831
832 A "URI", http://spam.org, see [eggs2000] (in Bacon
833 [Publisher]). Also see "http://eggs.org", http://eggs.org.
834
835 .. [eggs2000] "Spam, Spam, Spam, Eggs, Bacon, and Spam"
836
837 4. reStructuredText syntax::
838
839 4. A URI_, see [eggs2000]_ (in Bacon [Publisher]).
840 Also see http://eggs.org.
841
842 .. _URI: http:/spam.org
843 .. [eggs2000] "Spam, Spam, Spam, Eggs, Bacon, and Spam"
844
845 The bracketed text '[Publisher]' may be problematic with
846 StructuredText (syntax 2 & 3).
847
848 reStructuredText's syntax (#4) is definitely the most readable. The
849 text is separated from the link URI and the footnote, resulting in
850 cleanly readable text.
851
852 .. _StructuredText: https://zopestructuredtext.readthedocs.org/
853 .. _Setext: https://docutils.sourceforge.io/mirror/setext.html
854 .. _reStructuredText: https://docutils.sourceforge.io/rst.html
855 .. _detailed description:
856 http://homepage.ntlworld.com/tibsnjoan/docutils/STNG-format.html
857 .. _STMinus: http://www.cis.upenn.edu/~edloper/pydoc/stminus.html
858 .. _StructuredTextNG:
859 http://www.zope.org/DevHome/Members/jim/StructuredTextWiki/StructuredTextNG
860 .. _README: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/~checkout~/
861 python/python/dist/src/README
862 .. _Emacs table mode: http://table.sourceforge.net/
863 .. _reStructuredText Markup Specification:
864 ../../ref/rst/restructuredtext.html
865
866 .. Emacs settings
867
868 Local Variables:
869 mode: indented-text
870 mode: rst
871 indent-tabs-mode: nil
872 sentence-end-double-space: t
873 fill-column: 70
874 End: