1
==================================================
2
A Record of reStructuredText Syntax Alternatives
3
==================================================
5
:Contact: goodger@users.sourceforge.net
6
:Revision: $Revision: 1.27 $
7
:Date: $Date: 2004/04/23 01:06:20 $
8
:Copyright: This document has been placed in the public domain.
10
The following are ideas, alternatives, and justifications that were
11
considered for reStructuredText syntax, which did not originate with
12
Setext_ or StructuredText_. For an analysis of constructs which *did*
13
originate with StructuredText or Setext, please see `Problems With
14
StructuredText`_. See the `reStructuredText Markup Specification`_
15
for full details of the established syntax.
17
.. _Setext: http://docutils.sourceforge.net/mirror/setext.html
19
http://dev.zope.org/Members/jim/StructuredTextWiki/FrontPage
20
.. _Problems with StructuredText: problems.html
21
.. _reStructuredText Markup Specification: reStructuredText.html
30
This is the realm of the possible but questionably probable. These
31
ideas are kept here as a record of what has been proposed, for
32
posterity and in case any of them prove to be useful.
35
Compound Enumerated Lists
36
-------------------------
38
Allow for compound enumerators, such as "1.1." or "1.a." or "1(a)", to
39
allow for nested enumerated lists without indentation?
42
Sloppy Indentation of List Items
43
--------------------------------
45
Perhaps the indentation shouldn't be so strict. Currently, this is
51
Anything wrong with this? ::
60
Block quote. (no good: requires some indent relative to first
65
2. Have to carefully define where the literal block ends::
71
Hmm... Non-strict indentation isn't such a good idea.
74
Lazy Indentation of List Items
75
------------------------------
77
Another approach: Going back to the first draft of reStructuredText
78
(2000-11-27 post to Doc-SIG)::
80
- This is the fourth item of the main list (no blank line above).
81
The second line of this item is not indented relative to the
82
bullet, which precludes it from having a second paragraph.
84
Change that to *require* a blank line above and below, to reduce
85
ambiguity. This "loosening" may be added later, once the parser's
86
been nailed down. However, a serious drawback of this approach is to
87
limit the content of each list item to a single paragraph.
90
David's Idea for Lazy Indentation
91
`````````````````````````````````
93
Consider a paragraph in a word processor. It is a single logical line
94
of text which ends with a newline, soft-wrapped arbitrarily at the
95
right edge of the page or screen. We can think of a plaintext
96
paragraph in the same way, as a single logical line of text, ending
97
with two newlines (a blank line) instead of one, and which may contain
98
arbitrary line breaks (newlines) where it was accidentally
99
hard-wrapped by an application. We can compensate for the accidental
100
hard-wrapping by "unwrapping" every unindented second and subsequent
101
line. The indentation of the first line of a paragraph or list item
102
would determine the indentation for the entire element. Blank lines
103
would be required between list items when using lazy indentation.
105
The following example shows the lazy indentation of multiple body
108
- This is the first paragraph
109
of the first list item.
111
Here is the second paragraph
112
of the first list item.
114
- This is the first paragraph
115
of the second list item.
117
Here is the second paragraph
118
of the second list item.
120
A more complex example shows the limitations of lazy indentation::
122
- This is the first paragraph
123
of the first list item.
125
Next is a definition list item:
128
Definition. The indentation of the term is
129
required, as is the indentation of the definition's
132
When the definition extends to more than
133
one line, lazy indentation may occur. (This is the second
134
paragraph of the definition.)
136
- This is the first paragraph
137
of the second list item.
139
- Here is the first paragraph of
140
the first item of a nested list.
142
So this paragraph would be outside of the nested list,
143
but inside the second list item of the outer list.
145
But this paragraph is not part of the list at all.
147
And the ambiguity remains::
149
- Look at the hyphen at the beginning of the next line
150
- is it a second list item marker, or a dash in the text?
152
Similarly, we may want to refer to numbers inside enumerated
155
1. How many socks in a pair? There are
156
2. How many pants in a pair? Exactly
159
Literal blocks and block quotes would still require consistent
160
indentation for all their lines. For block quotes, we might be able
161
to get away with only requiring that the first line of each contained
162
element be indented. For example::
166
This is a paragraph inside a block quote.
167
Second and subsequent lines need not be indented at all.
169
- A bullet list inside
172
Second paragraph of the
173
bullet list inside the block quote.
175
Although feasible, this form of lazy indentation has problems. The
176
document structure and hierarchy is not obvious from the indentation,
177
making the source plaintext difficult to read. This will also make
178
keeping track of the indentation while writing difficult and
179
error-prone. However, these problems may be acceptable for Wikis and
180
email mode, where we may be able to rely on less complex structure
181
(few nested lists, for example).
184
Multiple Roles in Interpreted Text
185
----------------------------------
187
In reStructuredText, inline markup cannot be nested (yet; `see
188
below`__). This also applies to interpreted text. In order to
189
simultaneously combine multiple roles for a single piece of text, a
190
syntax extension would be necessary. Ideas:
194
`interpreted text`:role1,role2:
196
2. Suggested by Jason Diamond::
198
`interpreted text`:role1:role2:
200
If a document is so complex as to require nested inline markup,
201
perhaps another markup system should be considered. By design,
202
reStructuredText does not have the flexibility of XML.
204
__ `Nested Inline Markup`_
207
Parameterized Interpreted Text
208
------------------------------
210
In some cases it may be expedient to pass parameters to interpreted
211
text, analogous to function calls. Ideas:
213
1. Parameterize the interpreted text role itself (suggested by Jason
216
`interpreted text`:role1(foo=bar):
218
Positional parameters could also be supported::
220
`CSS`:acronym(Cascading Style Sheets): is used for HTML, and
221
`CSS`:acronym(Content Scrambling System): is used for DVDs.
223
Technical problem: current interpreted text syntax does not
224
recognize roles containing whitespace. Design problem: this smells
225
like programming language syntax, but reStructuredText is not a
226
programming language.
228
2. Put the parameters inside the interpreted text::
230
`CSS (Cascading Style Sheets)`:acronym: is used for HTML, and
231
`CSS (Content Scrambling System)`:acronym: is used for DVDs.
233
Although this could be defined on an individual basis (per role),
234
we ought to have a standard. Hyperlinks with embedded URIs already
235
use angle brackets; perhaps they could be used here too::
237
`CSS <Cascading Style Sheets>`:acronym: is used for HTML, and
238
`CSS <Content Scrambling System>`:acronym: is used for DVDs.
240
Do angle brackets connote URLs too much for this to be acceptable?
241
How about the "tag" connotation -- does it save them or doom them?
243
Does this push inline markup too far? Readability becomes a serious
244
issue. Substitutions may provide a better alternative (at the expense
245
of verbosity and duplication) by pulling the details out of the text
248
|CSS| is used for HTML, and |CSS-DVD| is used for DVDs.
250
.. |CSS| acronym:: Cascading Style Sheets
251
.. |CSS-DVD| acronym:: Content Scrambling System
254
----------------------------------------------------------------------
256
This whole idea may be going beyond the scope of reStructuredText.
257
Documents requiring this functionality may be better off using XML or
258
another markup system.
260
This argument comes up regularly when pushing the envelope of
261
reStructuredText syntax. I think it's a useful argument in that it
262
provides a check on creeping featurism. In many cases, the resulting
263
verbosity produces such unreadable plaintext that there's a natural
264
desire *not* to use it unless absolutely necessary. It's a matter of
265
finding the right balance.
268
Syntax for Interpreted Text Role Bindings
269
-----------------------------------------
271
The following syntax (idea from Jeffrey C. Jacobs) could be used to
272
associate directives with roles::
274
.. :rewrite: class:: rewrite
276
`She wore ribbons in her hair and it lay with streaks of
279
The syntax is similar to that of substitution declarations, and the
280
directive/role association may resolve implementation issues. The
281
semantics, ramifications, and implementation details would need to be
284
The example above would implement the "rewrite" role as adding a
285
``class="rewrite"`` attribute to the interpreted text ("inline"
286
element). The stylesheet would then pick up on the "class" attribute
287
to do the actual formatting.
289
The advantage of the new syntax would be flexibility. Uses other than
290
"class" may present themselves. The disadvantage is complexity:
291
having to implement new syntax for a relatively specialized operation,
292
and having new semantics in existing directives ("class::" would do
293
something different).
295
The `"role" directive`__ has been implemented.
297
__ http://docutils.sf.net/spec/rst/directives.html#role
303
Several people have suggested adding some form of character processing
306
* Some sort of automated replacement of ASCII sequences:
308
- ``--`` to em-dash (or ``--`` to en-dash, and ``---`` to em-dash).
309
- Convert quotes to curly quote entities. (Essentially impossible
310
for HTML? Unnecessary for TeX.)
311
- Various forms of ``:-)`` to smiley icons.
312
- ``"\ "`` to . Problem with line-wrapping though: it could
313
end up escaping the newline.
314
- Escaped newlines to <BR>.
315
- Escaped period or quote or dash as a disappearing catalyst to
316
allow character-level inline markup?
318
* XML-style character entities, such as "©" for the copyright
321
Docutils has no need of a character entity subsystem. Supporting
322
Unicode and text encodings, character entities should be directly
323
represented in the text: a copyright symbol should be represented by
324
the copyright symbol character. If this is not possible in an
325
authoring environment, a pre-processing stage can be added, or a table
326
of substitution definitions can be devised.
328
A "unicode" directive has been implemented to allow direct
329
specification of esoteric characters. In combination with the
330
substitution construct, "include" files defining common sets of
331
character entities can be defined and used. `A set of character
332
entity set definition files have been defined`__ (`tarball`__).
333
There's also `a description and instructions for use`__.
335
__ http://docutils.sf.net/tmp/charents/
336
__ http://docutils.sf.net/tmp/charents.tgz
337
__ http://docutils.sf.net/tmp/charents/README.html
339
To allow for `character-level inline markup`_, a limited form of
340
character processing has been added to the spec and parser: escaped
341
whitespace characters are removed from the processed document. Any
342
further character processing will be of this functional type, rather
343
than of the character-encoding type.
345
.. _character-level inline markup:
346
reStructuredText.html#character-level-inline-markup
350
.. text-replace:: "pattern" "replacement"
352
- Support Unicode "U+XXXX" codes.
353
- Support regexps, perhaps with alternative "regexp-replace"
355
- Flags for regexps; ":flags:" option, or individuals.
356
- Specifically, should the default be case-sensistive or
363
Prior to the syntax for field lists being finalized, several
364
alternatives were proposed.
366
1. Unadorned RFC822_ everywhere::
371
Advantages: clean, precedent (RFC822-compliant). Disadvantage:
372
ambiguous (these paragraphs are a prime example).
374
Conclusion: rejected.
376
2. Special case: use unadorned RFC822_ for the very first or very last
377
text block of a document::
383
The rest of the document...
386
Advantages: clean, precedent (RFC822-compliant). Disadvantages:
387
special case, flat (unnested) field lists only, still ambiguous::
390
Usage: cmdname [options] arg1 arg2 ...
392
We obviously *don't* want the like above to be interpreted as a
393
field list item. Or do we?
396
Conclusion: rejected for the general case, accepted for specific
397
contexts (PEPs, email).
406
Advantages: explicit and unambiguous, RFC822-compliant.
407
Disadvantage: cumbersome.
409
Conclusion: rejected for the general case (but such a directive
410
could certainly be written).
412
4. Use Javadoc-style::
418
Advantages: unambiguous, precedent, flexible. Disadvantages:
419
non-intuitive, ugly, not RFC822-compliant.
421
Conclusion: rejected.
423
5. Use leading colons::
428
Advantages: unambiguous, obvious (*almost* RFC822-compliant),
429
flexible, perhaps even elegant. Disadvantages: no precedent, not
430
quite RFC822-compliant.
432
Conclusion: accepted!
434
6. Use double colons::
439
Advantages: unambiguous, obvious? (*almost* RFC822-compliant),
440
flexible, similar to syntax already used for literal blocks and
441
directives. Disadvantages: no precedent, not quite
442
RFC822-compliant, similar to syntax already used for literal blocks
445
Conclusion: rejected because of the syntax similarity & conflicts.
447
Why is RFC822 compliance important? It's a universal Internet
448
standard, and super obvious. Also, I'd like to support the PEP format
449
(ulterior motive: get PEPs to use reStructuredText as their standard).
450
But it *would* be easy to get used to an alternative (easy even to
451
convert PEPs; probably harder to convert python-deviants ;-).
453
Unfortunately, without well-defined context (such as in email headers:
454
RFC822 only applies before any blank lines), the RFC822 format is
455
ambiguous. It is very common in ordinary text. To implement field
456
lists unambiguously, we need explicit syntax.
458
The following question was posed in a footnote:
460
Should "bibliographic field lists" be defined at the parser level,
461
or at the DPS transformation level? In other words, are they
462
reStructuredText-specific, or would they also be applicable to
463
another (many/every other?) syntax?
465
The answer is that bibliographic fields are a
466
reStructuredText-specific markup convention. Other syntaxes may
467
implement the bibliographic elements explicitly. For example, there
468
would be no need for such a transformation for an XML-based markup
471
.. _RFC822: http://www.rfc-editor.org/rfc/rfc822.txt
474
Interpreted Text "Roles"
475
========================
477
The original purpose of interpreted text was as a mechanism for
478
descriptive markup, to describe the nature or role of a word or
479
phrase. For example, in XML we could say "<function>len</function>"
480
to mark up "len" as a function. It is envisaged that within Python
481
docstrings (inline documentation in Python module source files, the
482
primary market for reStructuredText) the role of a piece of
483
interpreted text can be inferred implicitly from the context of the
484
docstring within the program source. For other applications, however,
485
the role may have to be indicated explicitly.
487
Interpreted text is enclosed in single backquotes (`).
489
1. Initially, it was proposed that an explicit role could be indicated
490
as a word or phrase within the enclosing backquotes:
492
- As a prefix, separated by a colon and whitespace::
494
`role: interpreted text`
496
- As a suffix, separated by whitespace and a colon::
498
`interpreted text :role`
500
There are problems with the initial approach:
502
- There could be ambiguity with interpreted text containing colons.
503
For example, an index entry of "Mission: Impossible" would
504
require a backslash-escaped colon.
506
- The explicit role is descriptive markup, not content, and will
507
not be visible in the processed output. Putting it inside the
508
backquotes doesn't feel right; the *role* isn't being quoted.
510
2. Tony Ibbs suggested that the role be placed outside the
513
role:`prefix` or `suffix`:role
515
This removes the embedded-colons ambiguity, but limits the role
516
identifier to be a single word (whitespace would be illegal).
517
Since roles are not meant to be visible after processing, the lack
518
of whitespace support is not important.
520
The suggested syntax remains ambiguous with respect to ratios and
521
some writing styles. For example, suppose there is a "signal"
522
identifier, and we write::
524
...calculate the `signal`:noise ratio.
526
"noise" looks like a role.
528
3. As an improvement on #2, we can bracket the role with colons::
530
:role:`prefix` or `suffix`:role:
532
This syntax is similar to that of field lists, which is fine since
533
both are doing similar things: describing.
535
This is the syntax chosen for reStructuredText.
537
4. Another alternative is two colons instead of one::
539
role::`prefix` or `suffix`::role
541
But this is used for analogies ("A:B::C:D": "A is to B as C is to
544
Both alternative #2 and #4 lack delimiters on both sides of the
545
role, making it difficult to parse (by the reader).
547
5. Some kind of bracketing could be used:
551
(role)`prefix` or `suffix`(role)
555
{role}`prefix` or `suffix`{role}
559
[role]`prefix` or `suffix`[role]
563
<role>`prefix` or `suffix`<role>
565
(The overlap of \*ML tags with angle brackets would be too
566
confusing and precludes their use.)
568
Syntax #3 was chosen for reStructuredText.
574
A problem with comments (actually, with all indented constructs) is
575
that they cannot be followed by an indented block -- a block quote --
576
without swallowing it up.
578
I thought that perhaps comments should be one-liners only. But would
579
this mean that footnotes, hyperlink targets, and directives must then
580
also be one-liners? Not a good solution.
582
Tony Ibbs suggested a "comment" directive. I added that we could
583
limit a comment to a single text block, and that a "multi-block
584
comment" could use "comment-start" and "comment-end" directives. This
585
would remove the indentation incompatibility. A "comment" directive
586
automatically suggests "footnote" and (hyperlink) "target" directives
587
as well. This could go on forever! Bad choice.
589
Garth Kidd suggested that an "empty comment", a ".." explicit markup
590
start with nothing on the first line (except possibly whitespace) and
591
a blank line immediately following, could serve as an "unindent". An
592
empty comment does **not** swallow up indented blocks following it,
593
so block quotes are safe. "A tiny but practical wart." Accepted.
599
Alan Jaffray came up with this idea, along with the following syntax::
601
Search the `Python DOC-SIG mailing list archives`{}_.
603
.. _: http://mail.python.org/pipermail/doc-sig/
605
The idea is sound and useful. I suggested a "double underscore"
608
Search the `Python DOC-SIG mailing list archives`__.
610
.. __: http://mail.python.org/pipermail/doc-sig/
612
But perhaps single underscores are okay? The syntax looks better, but
613
the hyperlink itself doesn't explicitly say "anonymous"::
615
Search the `Python DOC-SIG mailing list archives`_.
617
.. _: http://mail.python.org/pipermail/doc-sig/
619
Mixing anonymous and named hyperlinks becomes confusing. The order of
620
targets is not significant for named hyperlinks, but it is for
621
anonymous hyperlinks::
623
Hyperlinks: anonymous_, named_, and another anonymous_.
629
Without the extra syntax of double underscores, determining which
630
hyperlink references are anonymous may be difficult. We'd have to
631
check which references don't have corresponding targets, and match
632
those up with anonymous targets. Keeping to a simple consistent
633
ordering (as with auto-numbered footnotes) seems simplest.
635
reStructuredText will use the explicit double-underscore syntax for
636
anonymous hyperlinks. An alternative (see `Reworking Explicit Markup
637
(Round 1)`_ below) for the somewhat awkward ".. __:" syntax is "__"::
639
An anonymous__ reference.
644
Reworking Explicit Markup (Round 1)
645
===================================
647
Alan Jaffray came up with the idea of `anonymous hyperlinks`_, added
648
to reStructuredText. Subsequently it was asserted that hyperlinks
649
(especially anonymous hyperlinks) would play an increasingly important
650
role in reStructuredText documents, and therefore they require a
651
simpler and more concise syntax. This prompted a review of the
652
current and proposed explicit markup syntaxes with regards to
657
.. _blah: internal hyperlink target
658
.. _blah: http://somewhere external hyperlink target
659
.. _blah: blahblah_ indirect hyperlink target
660
.. __: anonymous internal target
661
.. __: http://somewhere anonymous external target
662
.. __: blahblah_ anonymous indirect target
663
.. [blah] http://somewhere footnote
664
.. blah:: http://somewhere directive
665
.. blah: http://somewhere comment
669
The comment text was intentionally made to look like a hyperlink
674
* Except for the colon (a delimiter necessary to allow for
675
phrase-links), hyperlink target ``.. _blah:`` comes from Setext.
676
* Comment syntax from Setext.
677
* Footnote syntax from StructuredText ("named links").
678
* Directives and anonymous hyperlinks original to reStructuredText.
682
+ Consistent explicit markup indicator: "..".
683
+ Consistent hyperlink syntax: ".. _" & ":".
687
- Anonymous target markup is awkward: ".. __:".
688
- The explicit markup indicator ("..") is excessively overloaded?
689
- Comment text is limited (can't look like a footnote, hyperlink,
690
or directive). But this is probably not important.
692
2. Alan Jaffray's proposed syntax #1::
694
__ _blah internal hyperlink target
695
__ blah: http://somewhere external hyperlink target
696
__ blah: blahblah_ indirect hyperlink target
697
__ anonymous internal target
698
__ http://somewhere anonymous external target
699
__ blahblah_ anonymous indirect target
700
__ [blah] http://somewhere footnote
701
.. blah:: http://somewhere directive
702
.. blah: http://somewhere comment
704
The hyperlink-connoted underscores have become first-level syntax.
708
+ Anonymous targets are simpler.
709
+ All hyperlink targets are one character shorter.
713
- Inconsistent internal hyperlink targets. Unlike all other named
714
hyperlink targets, there's no colon. There's an extra leading
715
underscore, but we can't drop it because without it, "blah" looks
716
like a relative URI. Unless we restore the colon::
718
__ blah: internal hyperlink target
722
3. Alan Jaffray's proposed syntax #2::
724
.. _blah internal hyperlink target
725
.. blah: http://somewhere external hyperlink target
726
.. blah: blahblah_ indirect hyperlink target
727
.. anonymous internal target
728
.. http://somewhere anonymous external target
729
.. blahblah_ anonymous indirect target
730
.. [blah] http://somewhere footnote
731
!! blah: http://somewhere directive
732
## blah: http://somewhere comment
734
Leading underscores have been (almost) replaced by "..", while
735
comments and directives have gained their own syntax.
739
+ Anonymous hyperlinks are simpler.
740
+ Unique syntax for comments. Connotation of "comment" from
741
some programming languages (including our favorite).
742
+ Unique syntax for directives. Connotation of "action!".
746
- Inconsistent internal hyperlink targets. Again, unlike all other
747
named hyperlink targets, there's no colon. There's a leading
748
underscore, matching the trailing underscores of references,
749
which no other hyperlink targets have. We can't drop that one
750
leading underscore though: without it, "blah" looks like a
751
relative URI. Again, unless we restore the colon::
753
.. blah: internal hyperlink target
755
- All (except for internal) hyperlink targets lack their leading
756
underscores, losing the "hyperlink" connotation.
758
- Obtrusive syntax for comments. Alternatives::
760
;; blah: http://somewhere
761
(also comment syntax in Lisp & others)
762
,, blah: http://somewhere
763
("comma comma": sounds like "comment"!)
765
- Iffy syntax for directives. Alternatives?
767
4. Tony Ibbs' proposed syntax::
769
.. _blah: internal hyperlink target
770
.. _blah: http://somewhere external hyperlink target
771
.. _blah: blahblah_ indirect hyperlink target
772
.. anonymous internal target
773
.. http://somewhere anonymous external target
774
.. blahblah_ anonymous indirect target
775
.. [blah] http://somewhere footnote
776
.. blah:: http://somewhere directive
777
.. blah: http://somewhere comment
779
This is the same as the current syntax, except for anonymous
780
targets which drop their "__: ".
784
+ Anonymous targets are simpler.
788
- Anonymous targets lack their leading underscores, losing the
789
"hyperlink" connotation.
790
- Anonymous targets are almost indistinguishable from comments.
791
(Better to know "up front".)
793
5. David Goodger's proposed syntax: Perhaps going back to one of
794
Alan's earlier suggestions might be the best solution. How about
795
simply adding "__ " as a synonym for ".. __: " in the original
796
syntax? These would become equivalent::
798
.. __: anonymous internal target
799
.. __: http://somewhere anonymous external target
800
.. __: blahblah_ anonymous indirect target
802
__ anonymous internal target
803
__ http://somewhere anonymous external target
804
__ blahblah_ anonymous indirect target
806
Alternative 5 has been adopted.
809
Backquotes in Phrase-Links
810
==========================
812
[From a 2001-06-05 Doc-SIG post in reply to questions from Doug
815
The first draft of the spec, posted to the Doc-SIG in November 2000,
816
used square brackets for phrase-links. I changed my mind because:
818
1. In the first draft, I had already decided on single-backquotes for
821
2. However, I wanted to minimize the necessity for backslash escapes,
822
for example when quoting Python repr-equivalent syntax that uses
825
3. The processing of identifiers (function/method/attribute/module
826
etc. names) into hyperlinks is a useful feature. PyDoc recognizes
827
identifiers heuristically, but it doesn't take much imagination to
828
come up with counter-examples where PyDoc's heuristics would result
829
in embarassing failure. I wanted to do it deterministically, and
830
that called for syntax. I called this construct "interpreted
833
4. Leveraging off the ``*emphasis*/**strong**`` syntax, lead to the
834
idea of using double-backquotes as syntax.
836
5. I worked out some rules for inline markup recognition.
838
6. In combination with #5, double backquotes lent themselves to inline
839
literals, neatly satisfying #2, minimizing backslash escapes. In
840
fact, the spec says that no interpretation of any kind is done
841
within double-backquote inline literal text; backslashes do *no*
842
escaping within literal text.
844
7. Single backquotes are then freed up for interpreted text.
846
8. I already had square brackets required for footnote references.
848
9. Since interpreted text will typically turn into hyperlinks, it was
849
a natural fit to use backquotes as the phrase-quoting syntax for
850
trailing-underscore hyperlinks.
852
The original inspiration for the trailing underscore hyperlink syntax
853
was Setext. But for phrases Setext used a very cumbersome
854
``underscores_between_words_like_this_`` syntax.
856
The underscores can be viewed as if they were right-pointing arrows:
857
``-->``. So ``hyperlink_`` points away from the reference, and
858
``.. _hyperlink:`` points toward the target.
861
Substitution Mechanism
862
======================
864
Substitutions arose out of a Doc-SIG thread begun on 2001-10-28 by
865
Alan Jaffray, "reStructuredText inline markup". It reminded me of a
866
missing piece of the reStructuredText puzzle, first referred to in my
867
contribution to "Documentation markup & processing / PEPs" (Doc-SIG
870
Substitutions allow the power and flexibility of directives to be
871
shared by inline text. They are a way to allow arbitrarily complex
872
inline objects, while keeping the details out of the flow of text.
873
They are the equivalent of SGML/XML's named entities. For example, an
874
inline image (using reference syntax alternative 4d (vertical bars)
875
and definition alternative 3, the alternatives chosen for inclusion in
878
The |biohazard| symbol must be used on containers used to dispose
881
.. |biohazard| image:: biohazard.png
884
The ``|biohazard|`` substitution reference will be replaced in-line by
885
whatever the ``.. |biohazard|`` substitution definition generates (in
886
this case, an image). A substitution definition contains the
887
substitution text bracketed with vertical bars, followed by a an
888
embedded inline-compatible directive, such as "image". A transform is
889
required to complete the substitution.
891
Syntax alternatives for the reference:
893
1. Use the existing interpreted text syntax, with a predefined role
896
The `biohazard`:sub: symbol...
898
Advantages: existing syntax, explicit. Disadvantages: verbose,
901
2. Use a variant of the interpreted text syntax, with a new suffix
902
akin to the underscore in phrase-link references::
913
Due to incompatibility with other constructs and ordinary text
914
usage, (f) and (g) are not possible.
916
3. Use interpreted text syntax with a fixed internal format::
932
To avoid ML confusion (k) and (l) are definitely out. Square
933
brackets (j) won't work in the target (the substitution definition
934
would be indistinguishable from a footnote).
936
The ```/name/``` syntax (g) is reminiscent of "s/find/sub"
937
substitution syntax in ed-like languages. However, it may have a
938
misleading association with regexps, and looks like an absolute
939
POSIX path. (i) is visually equivalent and lacking the
942
A disadvantage of all of these is that they limit interpreted text,
943
albeit only slightly.
945
4. Use specialized syntax, something new::
962
"#" (a) and "@" (b) are obtrusive. "/" (c) without backquotes
963
looks just like a POSIX path; it is likely for such usage to appear
966
"|" (d) and "^" (h) are feasible.
968
5. Redefine the trailing underscore syntax. See definition syntax
969
alternative 4, below.
971
Syntax alternatives for the definition:
973
1. Use the existing directive syntax, with a predefined directive such
974
as "sub". It contains a further embedded directive resolving to an
975
inline-compatible object::
978
.. image:: biohazard.png
982
That bird wouldn't *voom* if you put 10,000,000 volts
985
The advantages and disadvantages are the same as in inline
988
2. Use syntax as in #1, but with an embedded directivecompressed::
990
.. sub:: biohazard image:: biohazard.png
993
This is a bit better than alternative 1, but still too much.
995
3. Use a variant of directive syntax, incorporating the substitution
996
text, obviating the need for a special "sub" directive name. If we
997
assume reference alternative 4d (vertical bars), the matching
998
definition would look like this::
1000
.. |biohazard| image:: biohazard.png
1001
[height=20 width=20]
1003
4. (Suggested by Alan Jaffray on Doc-SIG from 2001-11-06.)
1005
Instead of adding new syntax, redefine the trailing underscore
1006
syntax to mean "substitution reference" instead of "hyperlink
1007
reference". Alan's example::
1009
I had lunch with Jonathan_ today. We talked about Zope_.
1011
.. _Jonathan: lj [user=jhl]
1012
.. _Zope: http://www.zope.org/
1014
A problem with the proposed syntax is that URIs which look like
1015
simple reference names (alphanum plus ".", "-", "_") would be
1016
indistinguishable from substitution directive names. A more
1017
consistent syntax would be::
1019
I had lunch with Jonathan_ today. We talked about Zope_.
1021
.. _Jonathan: lj:: user=jhl
1022
.. _Zope: http://www.zope.org/
1024
(``::`` after ``.. _Jonathan: lj``.)
1026
The "Zope" target is a simple external hyperlink, but the
1027
"Jonathan" target contains a directive. Alan proposed is that the
1028
reference text be replaced by whatever the referenced directive
1029
(the "directive target") produces. A directive reference becomes a
1030
hyperlink reference if the contents of the directive target resolve
1031
to a hyperlink. If the directive target resolves to an icon, the
1032
reference is replaced by an inline icon. If the directive target
1033
resolves to a hyperlink, the directive reference becomes a
1034
hyperlink reference.
1036
This seems too indirect and complicated for easy comprehension.
1038
The reference in the text will sometimes become a link, sometimes
1039
not. Sometimes the reference text will remain, sometimes not. We
1040
don't know *at the reference*::
1042
This is a `hyperlink reference`_; its text will remain.
1043
This is an `inline icon`_; its text will disappear.
1047
The syntax that has been incorporated into the spec and parser is
1048
reference alternative 4d with definition alternative 3::
1050
The |biohazard| symbol...
1052
.. |biohazard| image:: biohazard.png
1053
[height=20 width=20]
1055
We can also combine substitution references with hyperlink references,
1056
by appending a "_" (named hyperlink reference) or "__" (anonymous
1057
hyperlink reference) suffix to the substitution reference. This
1058
allows us to click on an image-link::
1060
The |biohazard|_ symbol...
1062
.. |biohazard| image:: biohazard.png
1063
[height=20 width=20]
1064
.. _biohazard: http://www.cdc.gov/
1066
There have been several suggestions for the naming of these
1067
constructs, originally called "substitution references" and
1070
1. Candidate names for the reference construct:
1072
(a) substitution reference
1073
(b) tagging reference
1074
(c) inline directive reference
1075
(d) directive reference
1076
(e) indirect inline directive reference
1077
(f) inline directive placeholder
1078
(g) inline directive insertion reference
1079
(h) directive insertion reference
1080
(i) insertion reference
1081
(j) directive macro reference
1083
(l) substitution directive reference
1085
2. Candidate names for the definition construct:
1088
(b) substitution directive
1090
(d) tagged directive
1091
(e) directive target
1092
(f) inline directive
1093
(g) inline directive definition
1094
(h) referenced directive
1095
(i) indirect directive
1096
(j) indirect directive definition
1097
(k) directive definition
1098
(l) indirect inline directive
1099
(m) named directive definition
1100
(n) inline directive insertion definition
1101
(o) directive insertion definition
1102
(p) insertion definition
1103
(q) insertion directive
1104
(r) substitution definition
1105
(s) directive macro definition
1106
(t) macro definition
1107
(u) substitution directive definition
1108
(v) substitution definition
1110
"Inline directive reference" (1c) seems to be an appropriate term at
1111
first, but the term "inline" is redundant in the case of the
1112
reference. Its counterpart "inline directive definition" (2g) is
1113
awkward, because the directive definition itself is not inline.
1115
"Directive reference" (1d) and "directive definition" (2k) are too
1116
vague. "Directive definition" could be used to refer to any
1117
directive, not just those used for inline substitutions.
1119
One meaning of the term "macro" (1k, 2s, 2t) is too
1120
programming-language-specific. Also, macros are typically simple text
1121
substitution mechanisms: the text is substituted first and evaluated
1122
later. reStructuredText substitution definitions are evaluated in
1123
place at parse time and substituted afterwards.
1125
"Insertion" (1h, 1i, 2n-2q) is almost right, but it implies that
1126
something new is getting added rather than one construct being
1127
replaced by another.
1129
Which brings us back to "substitution". The overall best names are
1130
"substitution reference" (1a) and "substitution definition" (2v). A
1131
long way to go to add one word!
1137
As a further wrinkle (see `Reworking Explicit Markup (Round 1)`_
1138
above), in the wee hours of 2002-02-28 I posted several ideas for
1139
changes to footnote syntax:
1141
- Change footnote syntax from ``.. [1]`` to ``_[1]``? ...
1142
- Differentiate (with new DTD elements) author-date "citations"
1143
(``[GVR2002]``) from numbered footnotes? ...
1144
- Render footnote references as superscripts without "[]"? ...
1146
These ideas are all related, and suggest changes in the
1147
reStructuredText syntax as well as the docutils tree model.
1149
The footnote has been used for both true footnotes (asides expanding
1150
on points or defining terms) and for citations (references to external
1151
works). Rather than dealing with one amalgam construct, we could
1152
separate the current footnote concept into strict footnotes and
1153
citations. Citations could be interpreted and treated differently
1154
from footnotes. Footnotes would be limited to numerical labels:
1155
manual ("1") and auto-numbered (anonymous "#", named "#label").
1157
The footnote is the only explicit markup construct (starts with ".. ")
1158
that directly translates to a visible body element. I've always been
1159
a little bit uncomfortable with the ".. " marker for footnotes because
1160
of this; ".. " has a connotation of "special", but footnotes aren't
1161
especially "special". Printed texts often put footnotes at the bottom
1162
of the page where the reference occurs (thus "foot note"). Some HTML
1163
designs would leave footnotes to be rendered the same positions where
1164
they're defined. Other online and printed designs will gather
1165
footnotes into a section near the end of the document, converting them
1166
to "endnotes" (perhaps using a directive in our case); but this
1167
"special processing" is not an intrinsic property of the footnote
1168
itself, but a decision made by the document author or processing
1171
Citations are almost invariably collected in a section at the end of a
1172
document or section. Citations "disappear" from where they are
1173
defined and are magically reinserted at some well-defined point.
1174
There's more of a connection to the "special" connotation of the ".. "
1175
syntax. The point at which the list of citations is inserted could be
1176
defined manually by a directive (e.g., ".. citations::"), and/or have
1177
default behavior (e.g., a section automatically inserted at the end of
1178
the document) that might be influenced by options to the Writer.
1187
.. [#] Auto-numbered footnote.
1188
.. [#label] Auto-labeled footnote.
1190
- The syntax proposed in the original 2002-02-28 Doc-SIG post:
1191
remove the ".. ", prefix a "_"::
1194
_[#] Auto-numbered footnote.
1195
_[#label] Auto-labeled footnote.
1197
The leading underscore syntax (earlier dropped because
1198
``.. _[1]:`` was too verbose) is a useful reminder that footnotes
1199
are hyperlink targets.
1201
- Minimal syntax: remove the ".. [" and "]", prefix a "_", and
1205
_#. Auto-numbered footnote.
1206
_#label. Auto-labeled footnote.
1208
``_1.``, ``_#.``, and ``_#label.`` are markers,
1211
Footnotes could be rendered something like this in HTML
1213
| 1. This is a footnote. The brackets could be dropped
1214
| from the label, and a vertical bar could set them
1215
| off from the rest of the document in the HTML.
1217
Two-way hyperlinks on the footnote marker ("1." above) would also
1218
help to differentiate footnotes from enumerated lists.
1220
If converted to endnotes (by a directive/transform), a horizontal
1221
half-line might be used instead. Page-oriented output formats
1222
would typically use the horizontal line for true footnotes.
1224
+ Footnote references:
1228
[1]_, [#]_, [#label]_
1230
- Minimal syntax to match the minimal footnote syntax above::
1234
As a consequence, pure-numeric hyperlink references would not be
1235
possible; they'd be interpreted as footnote references.
1237
+ Citation references: no change is proposed from the current footnote
1244
- Current syntax (footnote syntax)::
1246
.. [GVR2001] Python Documentation; van Rossum, Drake, et al.;
1247
http://www.python.org/doc/
1249
- Possible new syntax::
1251
_[GVR2001] Python Documentation; van Rossum, Drake, et al.;
1252
http://www.python.org/doc/
1255
Docutils: Python Documentation Utilities project; Goodger
1256
et al.; http://docutils.sourceforge.net/
1258
Without the ".. " marker, subsequent lines would either have to
1259
align as in one of the above, or we'd have to allow loose
1260
alignment (I'd rather not)::
1262
_[GVR2001] Python Documentation; van Rossum, Drake, et al.;
1263
http://www.python.org/doc/
1265
I proposed adopting the "minimal" syntax for footnotes and footnote
1266
references, and adding citations and citation references to
1267
reStructuredText's repertoire. The current footnote syntax for
1268
citations is better than the alternatives given.
1270
From a reply by Tony Ibbs on 2002-03-01:
1272
However, I think easier with examples, so let's create one::
1274
Fans of Terry Pratchett are perhaps more likely to use
1275
footnotes [1]_ in their own writings than other people
1276
[2]_. Of course, in *general*, one only sees footnotes
1277
in academic or technical writing - it's use in fiction
1278
and letter writing is not normally considered good
1279
style [4]_, particularly in emails (not a medium that
1280
lends itself to footnotes).
1282
.. [1] That is, little bits of referenced text at the
1284
.. [2] Because Terry himself does, of course [3]_.
1285
.. [3] Although he has the distinction of being
1286
*funny* when he does it, and his fans don't always
1288
.. [4] Presumably because it detracts from linear
1289
reading of the text - this is, of course, the point.
1291
and look at it with the second syntax proposal::
1293
Fans of Terry Pratchett are perhaps more likely to use
1294
footnotes [1]_ in their own writings than other people
1295
[2]_. Of course, in *general*, one only sees footnotes
1296
in academic or technical writing - it's use in fiction
1297
and letter writing is not normally considered good
1298
style [4]_, particularly in emails (not a medium that
1299
lends itself to footnotes).
1301
_[1] That is, little bits of referenced text at the
1303
_[2] Because Terry himself does, of course [3]_.
1304
_[3] Although he has the distinction of being
1305
*funny* when he does it, and his fans don't always
1307
_[4] Presumably because it detracts from linear
1308
reading of the text - this is, of course, the point.
1310
(I note here that if I have gotten the indentation of the
1311
footnotes themselves correct, this is clearly not as nice. And if
1312
the indentation should be to the left margin instead, I like that
1315
and the third (new) proposal::
1317
Fans of Terry Pratchett are perhaps more likely to use
1318
footnotes 1_ in their own writings than other people
1319
2_. Of course, in *general*, one only sees footnotes
1320
in academic or technical writing - it's use in fiction
1321
and letter writing is not normally considered good
1322
style 4_, particularly in emails (not a medium that
1323
lends itself to footnotes).
1325
_1. That is, little bits of referenced text at the
1327
_2. Because Terry himself does, of course 3_.
1328
_3. Although he has the distinction of being
1329
*funny* when he does it, and his fans don't always
1331
_4. Presumably because it detracts from linear
1332
reading of the text - this is, of course, the point.
1334
I think I don't, in practice, mind the targets too much (the use
1335
of a dot after the number helps a lot here), but I do have a
1336
problem with the body text, in that I don't naturally separate out
1337
the footnotes as different than the rest of the text - instead I
1338
keep wondering why there are numbers interspered in the text. The
1339
use of brackets around the numbers ([ and ]) made me somehow parse
1340
the footnote references as "odd" - i.e., not part of the body text
1341
- and thus both easier to skip, and also (paradoxically) easier to
1342
pick out so that I could follow them.
1344
Thus, for the moment (and as always susceptable to argument), I'd
1345
say -1 on the new form of footnote reference (i.e., I much prefer
1346
the existing ``[1]_`` over the proposed ``1_``), and ambivalent
1347
over the proposed target change.
1349
That leaves David's problem of wanting to distinguish footnotes
1350
and citations - and the only thing I can propose there is that
1351
footnotes are numeric or # and citations are not (which, as a
1352
human being, I can probably cope with!).
1354
From a reply by Paul Moore on 2002-03-01:
1356
I think the current footnote syntax ``[1]_`` is *exactly* the
1357
right balance of distinctness vs unobtrusiveness. I very
1358
definitely don't think this should change.
1360
On the target change, it doesn't matter much to me.
1362
From a further reply by Tony Ibbs on 2002-03-01, referring to the
1363
"[1]" form and actual usage in email:
1365
Clearly this is a form people are used to, and thus we should
1366
consider it strongly (in the same way that the usage of ``*..*``
1367
to mean emphasis was taken partly from email practise).
1369
Equally clearly, there is something "magical" for people in the
1370
use of a similar form (i.e., ``[1]``) for both footnote reference
1371
and footnote target - it seems natural to keep them similar.
1375
I think that this established plaintext usage leads me to strongly
1376
believe we should retain square brackets at both ends of a
1377
footnote. The markup of the reference end (a single trailing
1378
underscore) seems about as minimal as we can get away with. The
1379
markup of the target end depends on how one envisages the thing -
1380
if ".." means "I am a target" (as I tend to see it), then that's
1381
good, but one can also argue that the "_[1]" syntax has a neat
1382
symmetry with the footnote reference itself, if one wishes (in
1383
which case ".." presumably means "hidden/special" as David seems
1384
to think, which is why one needs a ".." *and* a leading underline
1385
for hyperlink targets.
1387
Given the persuading arguments voiced, we'll leave footnote & footnote
1388
reference syntax alone. Except that these discussions gave rise to
1389
the "auto-symbol footnote" concept, which has been added. Citations
1390
and citation references have also been added.
1393
Auto-Enumerated Lists
1394
=====================
1396
The advantage of auto-numbered enumerated lists would be similar to
1397
that of auto-numbered footnotes: lists could be written and rearranged
1398
without having to manually renumber them. The disadvantages are also
1399
the same: input and output wouldn't match exactly; the markup may be
1400
ugly or confusing (depending on which alternative is chosen).
1402
1. Use the "#" symbol. Example::
1408
Advantages: simple, explicit. Disadvantage: enumeration sequence
1409
cannot be specified (limited to arabic numerals); ugly.
1411
2. As a variation on #1, first initialize the enumeration sequence?
1418
Advantages: simple, explicit, any enumeration sequence possible.
1419
Disadvantages: ugly; perhaps confusing with mixed concrete/abstract
1422
3. Alternative suggested by Fred Bremmer, from experience with MoinMoin::
1428
Advantages: enumeration sequence is explicit (could be multiple
1429
"a." or "(I)" tokens). Disadvantages: perhaps confusing; otherwise
1430
erroneous input (e.g., a duplicate item "1.") would pass silently,
1431
either causing a problem later in the list (if no blank lines
1432
between items) or creating two lists (with blanks).
1434
Take this input for example::
1438
1. Unintentional duplicate of item 1.
1442
Currently the parser will produce two list, "1" and "1,2" (no
1443
warnings, because of the presence of blank lines). Using Fred's
1444
notation, the current behavior is "1,1,2 -> 1 1,2" (without blank
1445
lines between items, it would be "1,1,2 -> 1 [WARNING] 1,2"). What
1446
should the behavior be with auto-numbering?
1448
Fred has produced a patch__, whose initial behavior is as follows::
1453
1,2,2,3 -> 1,2,3 [WARNING] 3
1454
1,1,2 -> 1,2 [WARNING] 2
1456
(After the "[WARNING]", the "3" would begin a new list.)
1458
I have mixed feelings about adding this functionality to the spec &
1459
parser. It would certainly be useful to some users (myself
1460
included; I often have to renumber lists). Perhaps it's too
1461
clever, asking the parser to guess too much. What if you *do* want
1462
three one-item lists in a row, each beginning with "1."? You'd
1463
have to use empty comments to force breaks. Also, I question
1464
whether "1,2,2 -> 1,2,3" is optimal behavior.
1466
In response, Fred came up with "a stricter and more explicit rule
1467
[which] would be to only auto-number silently if *all* the
1468
enumerators of a list were identical". In that case::
1471
1,2,2 -> 1,2 [WARNING] 2
1473
1,2,2,3 -> 1,2 [WARNING] 2,3
1474
1,1,2 -> 1,2 [WARNING] 2
1476
Should any start-value be allowed ("3,3,3"), or should
1477
auto-numbered lists be limited to begin with ordinal-1 ("1", "A",
1480
__ http://sourceforge.net/tracker/index.php?func=detail&aid=548802
1481
&group_id=38414&atid=422032
1483
4. Alternative proposed by Tony Ibbs::
1486
#3. Aha - I edited this in later.
1489
The initial proposal required unique enumerators within a list, but
1490
this limits the convenience of a feature of already limited
1491
applicability and convenience. Not a useful requirement; dropped.
1493
Instead, simply prepend a "#" to a standard list enumerator to
1494
indicate auto-enumeration. The numbers (or letters) of the
1495
enumerators themselves are not significant, except:
1497
- as a sequence indicator (arabic, roman, alphabetic; upper/lower),
1499
- and perhaps as a start value (first list item).
1501
Advantages: explicit, any enumeration sequence possible.
1502
Disadvantages: a bit ugly.
1505
Inline External Targets
1506
=======================
1508
Currently reStructuredText has two hyperlink syntax variations:
1510
* Named hyperlinks::
1512
This is a named reference_ of one word ("reference"). Here is
1513
a `phrase reference`_. Phrase references may even cross `line
1516
.. _reference: http://www.example.org/reference/
1517
.. _phrase reference: http://www.example.org/phrase_reference/
1518
.. _line boundaries: http://www.example.org/line_boundaries/
1522
- The plaintext is readable.
1523
- Each target may be reused multiple times (e.g., just write
1524
``"reference_"`` again).
1525
- No syncronized ordering of references and targets is necessary.
1529
- The reference text must be repeated as target names; could lead
1531
- The target URLs may be located far from the references, and hard
1532
to find in the plaintext.
1534
* Anonymous hyperlinks (in current reStructuredText)::
1536
This is an anonymous reference__. Here is an anonymous
1537
`phrase reference`__. Phrase references may even cross `line
1540
__ http://www.example.org/reference/
1541
__ http://www.example.org/phrase_reference/
1542
__ http://www.example.org/line_boundaries/
1546
- The plaintext is readable.
1547
- The reference text does not have to be repeated.
1551
- References and targets must be kept in sync.
1552
- Targets cannot be reused.
1553
- The target URLs may be located far from the references.
1555
For comparison and historical background, StructuredText also has two
1556
syntaxes for hyperlinks:
1558
* First, ``"reference text":URL``::
1560
This is a "reference":http://www.example.org/reference/
1561
of one word ("reference"). Here is a "phrase
1562
reference":http://www.example.org/phrase_reference/.
1564
* Second, ``"reference text", http://example.com/absolute_URL``::
1566
This is a "reference", http://www.example.org/reference/
1567
of one word ("reference"). Here is a "phrase reference",
1568
http://www.example.org/phrase_reference/.
1570
Both syntaxes share advantages and disadvantages:
1574
- The target is specified immediately adjacent to the reference.
1578
- Poor plaintext readability.
1579
- Targets cannot be reused.
1580
- Both syntaxes use double quotes, common in ordinary text.
1581
- In the first syntax, the URL and the last word are stuck
1582
together, exacerbating the line wrap problem.
1583
- The second syntax is too magical; text could easily be written
1584
that way by accident (although only absolute URLs are recognized
1585
here, perhaps because of the potential for ambiguity).
1587
A new type of "inline external hyperlink" has been proposed.
1589
1. On 2002-06-28, Simon Budig proposed__ a new syntax for
1590
reStructuredText hyperlinks::
1592
This is a reference_(http://www.example.org/reference/) of one
1593
word ("reference"). Here is a `phrase
1594
reference`_(http://www.example.org/phrase_reference/). Are
1595
these examples, (single-underscore), named? If so, `anonymous
1596
references`__(http://www.example.org/anonymous/) using two
1597
underscores would probably be preferable.
1599
__ http://mail.python.org/pipermail/doc-sig/2002-June/002648.html
1601
The syntax, advantages, and disadvantages are similar to those of
1606
- The target is specified immediately adjacent to the reference.
1610
- Poor plaintext readability.
1611
- Targets cannot be reused (unless named, but the semantics are
1616
- The ``"`ref`_(URL)"`` syntax forces the last word of the
1617
reference text to be joined to the URL, making a potentially
1618
very long word that can't be wrapped (URLs can be very long).
1619
The reference and the URL should be separate. This is a
1620
symptom of the following point:
1622
- The syntax produces a single compound construct made up of two
1623
equally important parts, *with syntax in the middle*, *between*
1624
the reference and the target. This is unprecedented in
1627
- The "inline hyperlink" text is *not* a named reference (there's
1628
no lookup by name), so it shouldn't look like one.
1630
- According to the IETF standards RFC 2396 and RFC 2732,
1631
parentheses are legal URI characters and curly braces are legal
1632
email characters, making their use prohibitively difficult.
1634
- The named/anonymous semantics are unclear.
1636
2. After an analysis__ of the syntax of (1) above, we came up with the
1637
following compromise syntax::
1639
This is an anonymous reference__
1640
__<http://www.example.org/reference/> of one word
1641
("reference"). Here is a `phrase reference`__
1642
__<http://www.example.org/phrase_reference/>. `Named
1643
references`_ _<http://www.example.org/anonymous/> use single
1646
__ http://mail.python.org/pipermail/doc-sig/2002-July/002670.html
1648
The syntax builds on that of the existing "inline internal
1649
targets": ``an _`inline internal target`.``
1653
- The target is specified immediately adjacent to the reference,
1654
improving maintainability:
1656
- References and targets are easily kept in sync.
1657
- The reference text does not have to be repeated.
1659
- The construct is executed in two parts: references identical to
1660
existing references, and targets that are new but not too big a
1661
stretch from current syntax.
1663
- There's overwhelming precedent for quoting URLs with angle
1668
- Poor plaintext readability.
1669
- Lots of "line noise".
1670
- Targets cannot be reused (unless named; see below).
1672
To alleviate the readability issue slightly, we could allow the
1673
target to appear later, such as after the end of the sentence::
1675
This is a named reference__ of one word ("reference").
1676
__<http://www.example.org/reference/> Here is a `phrase
1677
reference`__. __<http://www.example.org/phrase_reference/>
1679
Problem: this could only work for one reference at a time
1680
(reference/target pairs must be proximate [refA trgA refB trgB],
1681
not interleaved [refA refB trgA trgB] or nested [refA refB trgB
1682
trgA]). This variation is too problematic; references and inline
1683
external targets will have to be kept imediately adjacent (see (3)
1686
The ``"reference__ __<target>"`` syntax is actually for "anonymous
1687
inline external targets", emphasized by the double underscores. It
1688
follows that single trailing and leading underscores would lead to
1689
*implicitly named* inline external targets. This would allow the
1690
reuse of targets by name. So after ``"reference_ _<target>"``,
1691
another ``"reference_"`` would point to the same target.
1694
From RFC 2396 (URI syntax):
1696
The angle-bracket "<" and ">" and double-quote (")
1697
characters are excluded [from URIs] because they are often
1698
used as the delimiters around URI in text documents and
1701
Using <> angle brackets around each URI is especially
1702
recommended as a delimiting style for URI that contain
1705
From RFC 822 (email headers):
1707
Angle brackets ("<" and ">") are generally used to indicate
1708
the presence of a one machine-usable reference (e.g.,
1709
delimiting mailboxes), possibly including source-routing to
1712
3. If it is best for references and inline external targets to be
1713
immediately adjacent, then they might as well be integrated.
1714
Here's an alternative syntax embedding the target URL in the
1717
This is an anonymous `reference <http://www.example.org
1718
/reference/>`__ of one word ("reference"). Here is a `phrase
1719
reference <http://www.example.org/phrase_reference/>`__.
1721
Advantages and disadvantages are similar to those in (2).
1722
Readability is still an issue, but the syntax is a bit less
1723
heavyweight (reduced line noise). Backquotes are required, even
1724
for one-word references; the target URL is included within the
1725
reference text, forcing a phrase context.
1727
We'll call this variant "embedded URIs".
1729
Problem: how to refer to a title like "HTML Anchors: <a>" (which
1730
ends with an HTML/SGML/XML tag)? We could either require more
1731
syntax on the target (like ``"`reference text
1732
__<http://example.com/>`__"``), or require the odd conflicting
1733
title to be escaped (like ``"`HTML Anchors: \<a>`__"``). The
1734
latter seems preferable, and not too onerous.
1736
Similarly to (2) above, a single trailing underscore would convert
1737
the reference & inline external target from anonymous to implicitly
1738
named, allowing reuse of targets by name.
1740
I think this is the least objectionable of the syntax alternatives.
1742
Other syntax variations have been proposed (by Brett Cannon and Benja
1745
`phrase reference`->http://www.example.com
1747
`phrase reference`@http://www.example.com
1749
`phrase reference`__ ->http://www.example.com
1751
`phrase reference` [-> http://www.example.com]
1753
`phrase reference`__ [-> http://www.example.com]
1755
`phrase reference` <http://www.example.com>_
1757
None of these variations are clearly superior to #3 above. Some have
1758
problems that exclude their use.
1760
With any kind of inline external target syntax it comes down to the
1761
conflict between maintainability and plaintext readability. I don't
1762
see a major problem with reStructuredText's maintainability, and I
1763
don't want to sacrifice plaintext readability to "improve" it.
1765
The proponents of inline external targets want them for easily
1766
maintainable web pages. The arguments go something like this:
1768
- Named hyperlinks are difficult to maintain because the reference
1769
text is duplicated as the target name.
1771
To which I said, "So use anonymous hyperlinks."
1773
- Anonymous hyperlinks are difficult to maintain becuase the
1774
references and targets have to be kept in sync.
1776
"So keep the targets close to the references, grouped after each
1777
paragraph. Maintenance is trivial."
1779
- But targets grouped after paragraphs break the flow of text.
1781
"Surely less than URLs embedded in the text! And if the intent is
1782
to produce web pages, not readable plaintext, then who cares about
1785
Many participants have voiced their objections to the proposed syntax:
1787
Garth Kidd: "I strongly prefer the current way of doing it.
1788
Inline is spectactularly messy, IMHO."
1790
Tony Ibbs: "I vehemently agree... that the inline alternatives
1791
being suggested look messy - there are/were good reasons they've
1792
been taken out... I don't believe I would gain from the new
1795
Paul Moore: "I agree as well. The proposed syntax is far too
1796
punctuation-heavy, and any of the alternatives discussed are
1797
ambiguous or too subtle."
1799
Others have voiced their support:
1801
fantasai: "I agree with Simon. In many cases, though certainly
1802
not in all, I find parenthesizing the url in plain text flows
1803
better than relegating it to a footnote."
1805
Ken Manheimer: "I'd like to weigh in requesting some kind of easy,
1806
direct inline reference link."
1808
(Interesting that those *against* the proposal have been using
1809
reStructuredText for a while, and those *for* the proposal are either
1810
new to the list ["fantasai", background unknown] or longtime
1811
StructuredText users [Ken Manheimer].)
1813
I was initially ambivalent/against the proposed "inline external
1814
targets". I value reStructuredText's readability very highly, and
1815
although the proposed syntax offers convenience, I don't know if the
1816
convenience is worth the cost in ugliness. Does the proposed syntax
1817
compromise readability too much, or should the choice be left up to
1818
the author? Perhaps if the syntax is *allowed* but its use strongly
1819
*discouraged*, for aesthetic/readability reasons?
1821
After a great deal of thought and much input from users, I've decided
1822
that there are reasonable use cases for this construct. The
1823
documentation should strongly caution against its use in most
1824
situations, recommending independent block-level targets instead.
1825
Syntax #3 above ("embedded URIs") will be used.
1828
Doctree Representation of Transitions
1829
=====================================
1831
(Although not reStructuredText-specific, this section fits best in
1834
Having added the "horizontal rule" construct to the `reStructuredText
1835
Markup Specification`_, a decision had to be made as to how to reflect
1836
the construct in the implementation of the document tree. Given this
1848
The horizontal rule indicates a "transition" (in prose terms) or the
1849
start of a new "division". Before implementation, the parsed document
1853
<section name="document">
1858
-------- <--- error here
1862
There are several possibilities for the implementation:
1864
1. Implement horizontal rules as "divisions" or segments. A
1865
"division" is a title-less, non-hierarchical section. The first
1866
try at an implementation looked like this::
1869
<section name="document">
1878
But the two paragraphs are really at the same level; they shouldn't
1879
appear to be at different levels. There's really an invisible
1880
"first division". The horizontal rule splits the document body
1881
into two segments, which should be treated uniformly.
1883
2. Treating "divisions" uniformly brings us to the second
1887
<section name="document">
1897
With this change, documents and sections will directly contain
1898
divisions and sections, but not body elements. Only divisions will
1899
directly contain body elements. Even without a horizontal rule
1900
anywhere, the body elements of a document or section would be
1901
contained within a division element. This makes the document tree
1902
deeper. This is similar to the way HTML_ treats document contents:
1903
grouped within a ``<body>`` element.
1905
3. Implement them as "transitions", empty elements::
1908
<section name="document">
1917
A transition would be a "point element", not containing anything,
1918
only identifying a point within the document structure. This keeps
1919
the document tree flatter, but the idea of a "point element" like
1920
"transition" smells bad. A transition isn't a thing itself, it's
1921
the space between two divisions. However, transitions are a
1924
Solution 3 was chosen for incorporation into the document tree model.
1926
.. _HTML: http://www.w3.org/MarkUp/
1929
Nested Inline Markup
1930
====================
1932
These are collected notes on a long-discussed issue. The original
1933
mailing list messages should be referred to for details.
1935
* In a 2001-10-31 discussion I wrote:
1937
Try, for example, `Ed Loper's 2001-03-21 post`_, which details
1938
some rules for nested inline markup. I think the complexity is
1939
prohibitive for the marginal benefit. (And if you can understand
1940
that tree without going mad, you're a better man than I. ;-)
1942
Inline markup is already fragile. Allowing nested inline markup
1943
would only be asking for trouble IMHO. If it proves absolutely
1944
necessary, it can be added later. The rules for what can appear
1945
inside what must be well thought out first though.
1947
.. _Ed Loper's 2001-03-21 post:
1948
http://mail.python.org/pipermail/doc-sig/2001-March/001487.html
1950
-- http://mail.python.org/pipermail/doc-sig/2001-October/002354.html
1952
* In a 2001-11-09 Doc-SIG post, I wrote:
1954
The problem is that in the
1955
what-you-see-is-more-or-less-what-you-get markup language that
1956
is reStructuredText, the symbols used for inline markup ("*",
1957
"**", "`", "``", etc.) may preclude nesting.
1959
I've rethought this position. Nested markup is not precluded, just
1960
tricky. People and software parse "double and 'single' quotes" all
1961
the time. Continuing,
1963
I've thought over how we might implement nested inline
1964
markup. The first algorithm ("first identify the outer inline
1965
markup as we do now, then recursively scan for nested inline
1966
markup") won't work; counterexamples were given in my `last post
1967
<http://mail.python.org/pipermail/doc-sig/2001-November/002363.html>`__.
1969
The second algorithm makes my head hurt::
1972
scan for start-string
1975
scan for start or end string
1976
if new start string found:
1978
elif matching end string found:
1980
elif non-matching end string found:
1981
if its a markup error:
1983
elif the initial start-string was misinterpreted:
1984
# e.g. in this case: ***strong** in emphasis*
1985
restart with the other interpretation
1986
# but it might be several layers back ...
1989
This is similar to how the parser does section title
1990
recognition, but sections are much more regular and
1993
Bottom line is, I don't think the benefits are worth the effort,
1994
even if it is possible. I'm not going to try to write the code,
1995
at least not now. If somebody codes up a consistent, working,
1996
general solution, I'll be happy to consider it.
1998
-- http://mail.python.org/pipermail/doc-sig/2001-November/002388.html
2000
* In a `2003-05-06 Docutils-Users post`__ Paul Tremblay proposed a new
2001
syntax to allow for easier nesting. It eventually evolved into
2006
The duplication with the existing interpreted text syntax is
2009
__ http://article.gmane.org/gmane.text.docutils.user/317
2011
* Could the parser be extended to parse nested interpreted text? ::
2013
:emphasis:`Some emphasized text with :strong:`some more
2014
emphasized text` in it and **perhaps** :reference:`a link``
2016
* In a `2003-06-18 Docutils-Develop post`__, Mark Nodine reported on
2017
his implementation of a form of nested inline markup in his
2018
Perl-based parser (unpublished). He brought up some interesting
2019
ideas. The implementation was flawed, however, by the change in
2020
semantics required for backslash escapes.
2022
__ http://article.gmane.org/gmane.text.docutils.devel/795
2024
* Docutils-develop threads between David Abrahams, David Goodger, and
2025
Mark Nodine (beginning 2004-01-16__ and 2004-01-19__) hashed out
2026
many of the details of a potentially successful implementation, as
2027
described below. David Abrahams checked in code to the "nesting"
2028
branch of CVS, awaiting thorough review.
2030
__ http://thread.gmane.org/gmane.text.docutils.devel/1102
2031
__ http://thread.gmane.org/gmane.text.docutils.devel/1125
2033
It may be possible to accomplish nested inline markup in general with
2034
a more powerful inline markup parser. There may be some issues, but
2035
I'm not averse to the idea of nested inline markup in general. I just
2036
don't have the time or inclination to write a new parser now. Of
2037
course, a good patch would be welcome!
2039
I envisage something like this. Explicit-role interpreted text must
2040
be nestable. Prefix-based is probably preferred, since suffix-based
2041
will look like inline literals::
2043
``text`:role1:`:role2:
2045
But it can be disambiguated, so it ought to be left up to the author::
2047
`\ `text`:role1:`:role2:
2049
In addition, other forms of inline markup may be nested if
2052
*emphasized ``literal`` and |substitution ref| and link_*
2054
IOW, the parser ought to be as permissive as possible.
2057
Syntax for Line Blocks
2058
======================
2060
* An early idea: How about a literal-block-like prefix, perhaps
2061
"``;;``"? (It is, after all, a *semi-literal* literal block, no?)
2064
Take it away, Eric the Orchestra Leader! ;;
2066
A one, two, a one two three four
2068
Half a bee, philosophically,
2069
must, *ipso facto*, half not be.
2070
But half the bee has got to be,
2071
*vis a vis* its entity. D'you see?
2073
But can a bee be said to be
2074
or not to be an entire bee,
2075
when half the bee is not a bee,
2076
due to some ancient injury?
2082
* Another idea: in an ordinary paragraph, if the first line ends with
2083
a backslash (escaping the newline), interpret the entire paragraph
2084
as a verse block? For example::
2086
Add just one backslash\
2087
And this paragraph becomes
2090
(Awful, and arguably invalid, since in Japanese the word "haiku"
2091
contains three syllables not two.)
2093
This idea was superceded by the rules for escaped whitespace, useful
2094
for `character-level inline markup`_.
2096
* In a `2004-02-22 docutils-develop message`__, Jarno Elonen proposed
2097
a "plain list" syntax (and also provided a patch)::
2100
| President, SuperDuper Corp.
2103
__ http://thread.gmane.org/gmane.text.docutils.devel/1187
2105
This syntax is very natural. However, these "plain lists" seem very
2106
similar to line blocks, and I see so little intrinsic "list-ness"
2107
that I'm loathe to add a new object. I used the term "blurbs" to
2108
remove the "list" connotation from the originally proposed name.
2109
Perhaps line blocks could be refined to add the two properties they
2112
A) long lines wrap nicely
2113
B) HTML output doesn't look like program code in non-CSS web
2116
(A) is an issue of all 3 aspects of Docutils: syntax (construct
2117
behaviour), internal representation, and output. (B) is partly an
2118
issue of internal representation but mostly of output.
2120
ReStructuredText will redefine line blocks with the "|"-quoting
2121
syntax. The following is my current thinking.
2127
Perhaps line block syntax like this would do::
2131
| IMF: not decided yet, but probably one of the following:
2137
Note that the "nested" list does not have nested syntax (the "|" are
2138
not further indented); the leading whitespace would still be
2139
significant somehow (more below). As for long lines in the input,
2140
this could suffice::
2143
| Founder, President, Chief Executive Officer, Cook, Bottle
2144
Washer, and All-Round Great Guy
2148
The lack of "|" on the third line indicates that it's a continuation
2149
of the second line, wrapped.
2151
I don't see much point in allowing arbitrary nested content. Multiple
2152
paragraphs or bullet lists inside a "blurb" doesn't make sense to me.
2153
Simple nested line blocks should suffice.
2156
Internal Representation
2157
-----------------------
2159
Line blocks are currently represented as text blobs as follows::
2161
<!ELEMENT line_block %text.model;>
2162
<!ATTLIST line_block
2166
Instead, we could represent each line by a separate element::
2168
<!ELEMENT line_block (line+)>
2169
<!ATTLIST line_block %basic.atts;>
2171
<!ELEMENT line %text.model;>
2172
<!ATTLIST line %basic.atts;>
2174
We'd keep the significance of the leading whitespace of each line
2175
either by converting it to non-breaking spaces at output, or with a
2176
per-line margin. Non-breaking spaces are simpler (for HTML, anyway)
2177
but kludgey, and wouldn't support indented long lines that wrap. But
2178
should inter-word whitespace (i.e., not leading whitespace) be
2179
preserved? Currently it is preserved in line blocks.
2181
Representing a more complex line block may be tricky::
2183
| But can a bee be said to be
2184
| or not to be an entire bee,
2185
| when half the bee is not a bee,
2186
| due to some ancient injury?
2188
Perhaps the representation could allow for nested line blocks::
2190
<!ELEMENT line_block (line | line_block)+>
2192
With this model, leading whitespace would no longer be significant.
2193
Instead, left margins are implied by the nesting. The example above
2194
could be represented as follows::
2198
But can a bee be said to be
2201
or not to be an entire bee,
2204
when half the bee is not a bee,
2207
due to some ancient injury?
2209
I wasn't sure what to do about even more complex line blocks::
2217
How should that be parsed and nested? Should the first line have
2218
the same nesting level (== indentation in the output) as the fourth
2219
line, or the same as the last line? Mark Nodine suggested that such
2220
line blocks be parsed similarly to complexly-nested block quotes,
2221
which seems reasonable. In the example above, this would result in
2222
the nesting of first line matching the last line's nesting. In
2223
other words, the nesting would be relative to neighboring lines
2230
In HTML, line blocks are currently output as "<pre>" blocks, which
2231
gives us significant whitespace and line breaks, but doesn't allow
2232
long lines to wrap and causes monospaced output without stylesheets.
2233
Instead, we could output "<div>" elements parallelling the
2234
representation above, where each nested <div class="line_block"> would
2235
have an increased left margin (specified in the stylesheet).
2237
Jarno suggested the following HTML output::
2239
<div class="line_block">
2240
<span class="line">First, top level line</span><br class="hidden"/>
2241
<div class="line_block"><span class="hidden"> </span>
2242
<span class="line">Second, once nested</span><br class="hidden"/>
2243
<span class="line">Third, once nested</span><br class="hidden"/>
2249
The ``<br class="hidden" />`` and ``<span
2250
class="hidden"> </span>`` are meant to support non-CSS and
2251
non-graphical browsers. I understand the case for "br", but I'm not
2252
so sure about hidden " ". I question how much effort should be
2253
put toward supporting non-graphical and especially non-CSS browsers,
2254
at least for html4css1.py output.
2256
Should the lines themselves be ``<span>`` or ``<div>``? I don't like
2257
mixing inline and block-level elements.
2260
Reworking Explicit Markup (Round 2)
2261
===================================
2263
See `Reworking Explicit Markup (Round 1)`_ for an earlier discussion.
2265
In April 2004, a new thread becan on docutils-develop: `Inconsistency
2266
in RST markup`__. Several arguments were made; the first argument
2267
begat later arguments. Below, the arguments are paraphrased "in
2268
quotes", with responses.
2270
__ http://thread.gmane.org/gmane.text.docutils.devel/1386
2272
1. References and targets take this form::
2276
.. _targetname: stuff
2278
But footnotes, "which generate links just like targets do", are
2285
"Footnotes should be written as"::
2291
But they're not the same type of animal. That's not a "footnote
2292
target", it's a *footnote*. Being a target is not a footnote's
2293
primary purpose (an arguable point). It just happens to grow a
2294
target automatically, for convenience. Just as a section title::
2299
isn't a "title target", it's a *title*, which happens to grow a
2300
target automatically. The consistency is there, it's just deeper
2301
than at first glance.
2303
Also, ".. [1]" was chosen for footnote syntax because it closely
2304
resembles one form of actual footnote rendering. ".. _[1]:" is too
2305
verbose; excessive punctuation is required to get the job done.
2307
For more of the reasoning behind the syntax, see `Problems With
2308
StructuredText (Hyperlinks)
2309
<http://docutils.sf.net/spec/rst/problems.html#hyperlinks>`__ and
2310
`Reworking Footnotes`_.
2312
2. "I expect directives to also look like ``.. this:`` [one colon]
2313
because that also closely parallels the link and footnote target
2316
There are good reasons for the two-colon syntax:
2318
Two colons are used after the directive type for these reasons:
2320
- Two colons are distinctive, and unlikely to be used in common
2323
- Two colons avoids clashes with common comment text like::
2325
.. Danger: modify at your own risk!
2327
- If an implementation of reStructuredText does not recognize a
2328
directive (i.e., the directive-handler is not installed), a
2329
level-3 (error) system message is generated, and the entire
2330
directive block (including the directive itself) will be
2331
included as a literal block. Thus "::" is a natural choice.
2333
-- http://docutils.sf.net/spec/rst/reStructuredText.html#directives
2335
The last reason is not particularly compelling; it's more of a
2336
convenient coincidence or mnemonic.
2338
3. "Comments always seemed too easy. I almost never write comments.
2339
I'd have no problem writing '.. comment:' in front of my comments.
2340
In fact, it would probably be more readable, as comments *should*
2341
be set off strongly, because they are very different from normal
2344
Many people do use comments though, and some applications of
2345
reStructuredText require it. For example, all reStructuredText
2346
PEPs (and this document!) have an Emacs stanza at the bottom, in a
2347
comment. Having to write ".. comment::" would be very obtrusive.
2349
Comments *should* be dirt-easy to do. It should be easy to
2350
"comment out" a block of text. Comments in programming languages
2351
and other markup languages are invariably easy.
2353
Any author is welcome to preface their comments with "Comment:" or
2354
"Do Not Print" or "Note to Editor" or anything they like. A
2355
"comment" directive could easily be implemented. It might be
2356
confused with admonition directives, like "note" and "caution"
2357
though. In unrelated (and unpublished and unfinished) work, adding
2358
a "comment" directive as a true document element was considered::
2360
If structure is necessary, we could use a "comment" directive
2361
(to avoid nonsensical DTD changes, the "comment" directive
2362
could produce an untitled topic element).
2364
4. "One of the goals of reStructuredText is to be *readable* by people
2365
who don't know it. This construction violates that: it is not at
2366
all obvious to the uninitiated that text marked by '..' is a
2367
comment. On the other hand, '.. comment:' would be totally
2370
Totally transparent, perhaps, but also very obtrusive. Another of
2371
`reStructuredText's goals`_ is to be unobtrusive, and
2372
".. comment::" would violate that. The goals of reStructuredText
2373
are many, and they conflict. Determining the right set of goals
2374
and finding solutions that best fit is done on a case-by-case
2377
Even readability is has two aspects. Being readable without any
2378
prior knowledge is one. Being as easily read in raw form as in
2379
processed form is the other. ".." may not contribute to the former
2380
aspect, but ".. comment::" would certainly detract from the latter.
2383
.. _reStructuredText's goals:
2384
http://docutils.sf.net/spec/rst/introduction.html#goals
2386
5. "Recently I sent someone an rst document, and they got confused; I
2387
had to explain to them that '..' marks comments, *unless* it's a
2390
The explanation of directives *is* roundabout, defining comments in
2391
terms of not being other things. That's definitely a wart.
2393
6. "Under the current system, a mistyped directive (with ':' instead
2394
of '::') will be silently ignored. This is an error that could
2395
easily go unnoticed."
2397
A parser option/setting like "--comments-on-stderr" would help.
2399
7. "I'd prefer to see double-dot-space / command / double-colon as the
2400
standard Docutils markup-marker. It's unusual enough to avoid
2401
being accidently used. Everything that starts with a double-dot
2402
should end with a double-colon."
2404
That would increase the punctuation verbosity of some constructs
2407
8. Edward Loper proposed the following plan for backwards
2410
1. ".. foo" will generate a deprecation warning to stderr, and
2411
nothing in the output (no system messages).
2412
2. ".. foo: bar" will be treated as a directive foo. If there
2413
is no foo directive, then do the normal error output.
2414
3. ".. foo:: bar" will generate a deprecation warning to
2415
stderr, and be treated as a directive. Or leave it valid?
2417
So some existing documents might start printing deprecation
2418
warnings, but the only existing documents that would *break*
2419
would be ones that say something like::
2421
.. warning: this should be a comment
2425
.. warning:: this should be a comment
2427
Here, we're trading fairly common a silent error (directive
2428
falsely treated as a comment) for a fairly uncommon explicitly
2429
flagged error (comment falsely treated as directive). To make
2430
things even easier, we could add a sentence to the
2431
unknown-directive error. Something like "If you intended to
2432
create a comment, please use '.. comment:' instead".
2434
On one hand, I understand and sympathize with the points raised. On
2435
the other hand, I think the current syntax strikes the right balance
2436
(but I acknowledge a possible lack of objectivity). On the gripping
2437
hand, the comment and directive syntax has become well established, so
2438
even if it's a wart, it may be a wart we have to live with.
2440
Making any of these changes would cause a lot of breakage or at least
2441
deprecation warnings. I'm not sure the benefit is worth the cost.
2443
For now, we'll treat this as an unresolved legacy issue.
2449
indent-tabs-mode: nil
2450
sentence-end-double-space: t