| 1 |
===================================== |
| 2 |
An Introduction to reStructuredText |
| 3 |
===================================== |
| 4 |
:Author: David Goodger |
| 5 |
:Contact: [email protected] |
| 6 |
:Revision: $Revision: 8959 $ |
| 7 |
:Date: $Date: 2022-01-21 14:45:42 +0100 (Fr, 21. Jän 2022) $ |
| 8 |
:Copyright: This document has been placed in the public domain. |
| 9 |
|
| 10 |
reStructuredText_ is an easy-to-read, what-you-see-is-what-you-get |
| 11 |
plaintext markup syntax and parser system. It is useful for inline |
| 12 |
program documentation (such as Python docstrings), for quickly |
| 13 |
creating simple web pages, and for standalone documents. |
| 14 |
reStructuredText_ is a proposed revision and reinterpretation of the |
| 15 |
StructuredText_ and Setext_ lightweight markup systems. |
| 16 |
|
| 17 |
reStructuredText is designed for extensibility for specific |
| 18 |
application domains. Its parser is a component of Docutils_. |
| 19 |
|
| 20 |
This document defines the goals_ of reStructuredText and provides a |
| 21 |
history_ of the project. It is written using the reStructuredText |
| 22 |
markup, and therefore serves as an example of its use. For a gentle |
| 23 |
introduction to using reStructuredText, please read `A |
| 24 |
ReStructuredText Primer`_. The `Quick reStructuredText`_ user |
| 25 |
reference is also useful. The `reStructuredText Markup |
| 26 |
Specification`_ is the definitive reference. There is also an |
| 27 |
analysis of the `Problems With StructuredText`_. |
| 28 |
|
| 29 |
ReStructuredText's web page is |
| 30 |
https://docutils.sourceforge.io/rst.html. |
| 31 |
|
| 32 |
.. _reStructuredText: https://docutils.sourceforge.io/rst.html |
| 33 |
.. _StructuredText: https://zopestructuredtext.readthedocs.org/ |
| 34 |
.. _Setext: https://docutils.sourceforge.io/mirror/setext.html |
| 35 |
.. _Docutils: https://docutils.sourceforge.io/ |
| 36 |
.. _A ReStructuredText Primer: ../../user/rst/quickstart.html |
| 37 |
.. _Quick reStructuredText: ../../user/rst/quickref.html |
| 38 |
.. _reStructuredText Markup Specification: restructuredtext.html |
| 39 |
.. _Problems with StructuredText: ../../dev/rst/problems.html |
| 40 |
|
| 41 |
|
| 42 |
Goals |
| 43 |
===== |
| 44 |
|
| 45 |
The primary goal of reStructuredText_ is to define a markup syntax for |
| 46 |
use in Python docstrings and other documentation domains, that is |
| 47 |
readable and simple, yet powerful enough for non-trivial use. The |
| 48 |
intended purpose of the reStructuredText markup is twofold: |
| 49 |
|
| 50 |
- the establishment of a set of standard conventions allowing the |
| 51 |
expression of structure within plaintext, and |
| 52 |
|
| 53 |
- the conversion of such documents into useful structured data |
| 54 |
formats. |
| 55 |
|
| 56 |
The secondary goal of reStructuredText is to be accepted by the Python |
| 57 |
community (by way of being blessed by PythonLabs and the BDFL [#]_) as |
| 58 |
a standard for Python inline documentation (possibly one of several |
| 59 |
standards, to account for taste). |
| 60 |
|
| 61 |
.. [#] Python's creator and "Benevolent Dictator For Life", |
| 62 |
Guido van Rossum. |
| 63 |
|
| 64 |
To clarify the primary goal, here are specific design goals, in order, |
| 65 |
beginning with the most important: |
| 66 |
|
| 67 |
1. Readable. The marked-up text must be easy to read without any |
| 68 |
prior knowledge of the markup language. It should be as easily |
| 69 |
read in raw form as in processed form. |
| 70 |
|
| 71 |
2. Unobtrusive. The markup that is used should be as simple and |
| 72 |
unobtrusive as possible. The simplicity of markup constructs |
| 73 |
should be roughly proportional to their frequency of use. The most |
| 74 |
common constructs, with natural and obvious markup, should be the |
| 75 |
simplest and most unobtrusive. Less common constructs, for which |
| 76 |
there is no natural or obvious markup, should be distinctive. |
| 77 |
|
| 78 |
3. Unambiguous. The rules for markup must not be open for |
| 79 |
interpretation. For any given input, there should be one and only |
| 80 |
one possible output (including error output). |
| 81 |
|
| 82 |
4. Unsurprising. Markup constructs should not cause unexpected output |
| 83 |
upon processing. As a fallback, there must be a way to prevent |
| 84 |
unwanted markup processing when a markup construct is used in a |
| 85 |
non-markup context (for example, when documenting the markup syntax |
| 86 |
itself). |
| 87 |
|
| 88 |
5. Intuitive. Markup should be as obvious and easily remembered as |
| 89 |
possible, for the author as well as for the reader. Constructs |
| 90 |
should take their cues from such naturally occurring sources as |
| 91 |
plaintext email messages, newsgroup postings, and text |
| 92 |
documentation such as README.txt files. |
| 93 |
|
| 94 |
6. Easy. It should be easy to mark up text using any ordinary text |
| 95 |
editor. |
| 96 |
|
| 97 |
7. Scalable. The markup should be applicable regardless of the length |
| 98 |
of the text. |
| 99 |
|
| 100 |
8. Powerful. The markup should provide enough constructs to produce a |
| 101 |
reasonably rich structured document. |
| 102 |
|
| 103 |
9. Language-neutral. The markup should apply to multiple natural (as |
| 104 |
well as artificial) languages, not only English. |
| 105 |
|
| 106 |
10. Extensible. The markup should provide a simple syntax and |
| 107 |
interface for adding more complex general markup, and custom |
| 108 |
markup. |
| 109 |
|
| 110 |
11. Output-format-neutral. The markup will be appropriate for |
| 111 |
processing to multiple output formats, and will not be biased |
| 112 |
toward any particular format. |
| 113 |
|
| 114 |
The design goals above were used as criteria for accepting or |
| 115 |
rejecting syntax, or selecting between alternatives. |
| 116 |
|
| 117 |
It is emphatically *not* the goal of reStructuredText to define |
| 118 |
docstring semantics, such as docstring contents or docstring length. |
| 119 |
These issues are orthogonal to the markup syntax and beyond the scope |
| 120 |
of this specification. |
| 121 |
|
| 122 |
Also, it is not the goal of reStructuredText to maintain compatibility |
| 123 |
with StructuredText_ or Setext_. reStructuredText shamelessly steals |
| 124 |
their great ideas and ignores the not-so-great. |
| 125 |
|
| 126 |
Author's note: |
| 127 |
|
| 128 |
Due to the nature of the problem we're trying to solve (or, |
| 129 |
perhaps, due to the nature of the proposed solution), the above |
| 130 |
goals unavoidably conflict. I have tried to extract and distill |
| 131 |
the wisdom accumulated over the years in the Python Doc-SIG_ |
| 132 |
mailing list and elsewhere, to come up with a coherent and |
| 133 |
consistent set of syntax rules, and the above goals by which to |
| 134 |
measure them. |
| 135 |
|
| 136 |
There will inevitably be people who disagree with my particular |
| 137 |
choices. Some desire finer control over their markup, others |
| 138 |
prefer less. Some are concerned with very short docstrings, |
| 139 |
others with full-length documents. This specification is an |
| 140 |
effort to provide a reasonably rich set of markup constructs in a |
| 141 |
reasonably simple form, that should satisfy a reasonably large |
| 142 |
group of reasonable people. |
| 143 |
|
| 144 |
David Goodger ([email protected]), 2001-04-20 |
| 145 |
|
| 146 |
.. _Doc-SIG: https://www.python.org/sigs/doc-sig/ |
| 147 |
|
| 148 |
|
| 149 |
History |
| 150 |
======= |
| 151 |
|
| 152 |
reStructuredText_, the specification, is based on StructuredText_ and |
| 153 |
Setext_. StructuredText was developed by Jim Fulton of `Zope |
| 154 |
Corporation`_ (formerly Digital Creations) and first released in 1996. |
| 155 |
It is now released as a part of the open-source "Z Object Publishing |
| 156 |
Environment" (ZOPE_). Ian Feldman's and Tony Sanders' earlier Setext_ |
| 157 |
specification was either an influence on StructuredText or, by their |
| 158 |
similarities, at least evidence of the correctness of this approach. |
| 159 |
|
| 160 |
I discovered StructuredText_ in late 1999 while searching for a way to |
| 161 |
document the Python modules in one of my projects. Version 1.1 of |
| 162 |
StructuredText was included in Daniel Larsson's pythondoc_. Although |
| 163 |
I was not able to get pythondoc to work for me, I found StructuredText |
| 164 |
to be almost ideal for my needs. I joined the Python Doc-SIG_ |
| 165 |
(Documentation Special Interest Group) mailing list and found an |
| 166 |
ongoing discussion of the shortcomings of the StructuredText |
| 167 |
"standard". This discussion has been going on since the inception of |
| 168 |
the mailing list in 1996, and possibly predates it. |
| 169 |
|
| 170 |
I decided to modify the original module with my own extensions and |
| 171 |
some suggested by the Doc-SIG members. I soon realized that the |
| 172 |
module was not written with extension in mind, so I embarked upon a |
| 173 |
general reworking, including adapting it to the "re" regular |
| 174 |
expression module (the original inspiration for the name of this |
| 175 |
project). Soon after I completed the modifications, I discovered that |
| 176 |
StructuredText.py was up to version 1.23 in the ZOPE distribution. |
| 177 |
Implementing the new syntax extensions from version 1.23 proved to be |
| 178 |
an exercise in frustration, as the complexity of the module had become |
| 179 |
overwhelming. |
| 180 |
|
| 181 |
In 2000, development on StructuredTextNG ("Next Generation") began at |
| 182 |
`Zope Corporation`_ (then Digital Creations). It seems to have many |
| 183 |
improvements, but still suffers from many of the problems of classic |
| 184 |
StructuredText. |
| 185 |
|
| 186 |
I decided that a complete rewrite was in order, and even started a |
| 187 |
`reStructuredText SourceForge project`_ (now inactive). My |
| 188 |
motivations (the "itches" I aim to "scratch") are as follows: |
| 189 |
|
| 190 |
- I need a standard format for inline documentation of the programs I |
| 191 |
write. This inline documentation has to be convertible to other |
| 192 |
useful formats, such as HTML. I believe many others have the same |
| 193 |
need. |
| 194 |
|
| 195 |
- I believe in the Setext/StructuredText idea and want to help |
| 196 |
formalize the standard. However, I feel the current specifications |
| 197 |
and implementations have flaws that desperately need fixing. |
| 198 |
|
| 199 |
- reStructuredText could form part of the foundation for a |
| 200 |
documentation extraction and processing system, greatly benefitting |
| 201 |
Python. But it is only a part, not the whole. reStructuredText is |
| 202 |
a markup language specification and a reference parser |
| 203 |
implementation, but it does not aspire to be the entire system. I |
| 204 |
don't want reStructuredText or a hypothetical Python documentation |
| 205 |
processor to die stillborn because of over-ambition. |
| 206 |
|
| 207 |
- Most of all, I want to help ease the documentation chore, the bane |
| 208 |
of many a programmer. |
| 209 |
|
| 210 |
Unfortunately I was sidetracked and stopped working on this project. |
| 211 |
In November 2000 I made the time to enumerate the problems of |
| 212 |
StructuredText and possible solutions, and complete the first draft of |
| 213 |
a specification. This first draft was posted to the Doc-SIG in three |
| 214 |
parts: |
| 215 |
|
| 216 |
- `A Plan for Structured Text`__ |
| 217 |
- `Problems With StructuredText`__ |
| 218 |
- `reStructuredText: Revised Structured Text Specification`__ |
| 219 |
|
| 220 |
__ https://mail.python.org/pipermail/doc-sig/2000-November/001239.html |
| 221 |
__ https://mail.python.org/pipermail/doc-sig/2000-November/001240.html |
| 222 |
__ https://mail.python.org/pipermail/doc-sig/2000-November/001241.html |
| 223 |
|
| 224 |
In March 2001 a flurry of activity on the Doc-SIG spurred me to |
| 225 |
further revise and refine my specification, the result of which you |
| 226 |
are now reading. An offshoot of the reStructuredText project has been |
| 227 |
the realization that a single markup scheme, no matter how well |
| 228 |
thought out, may not be enough. In order to tame the endless debates |
| 229 |
on Doc-SIG, a flexible `Docstring Processing System framework`_ needed |
| 230 |
to be constructed. This framework has become the more important of |
| 231 |
the two projects; reStructuredText_ has found its place as one |
| 232 |
possible choice for a single component of the larger framework. |
| 233 |
|
| 234 |
The project web site and the first project release were rolled out in |
| 235 |
June 2001, including posting the second draft of the spec [#spec-2]_ |
| 236 |
and the first draft of PEPs 256, 257, and 258 [#peps-1]_ to the |
| 237 |
Doc-SIG. These documents and the project implementation proceeded to |
| 238 |
evolve at a rapid pace. Implementation history details can be found |
| 239 |
in the `project history file`_. |
| 240 |
|
| 241 |
In November 2001, the reStructuredText parser was nearing completion. |
| 242 |
Development of the parser continued with the addition of small |
| 243 |
convenience features, improvements to the syntax, the filling in of |
| 244 |
gaps, and bug fixes. After a long holiday break, in early 2002 most |
| 245 |
development moved over to the other Docutils components, the |
| 246 |
"Readers", "Writers", and "Transforms". A "standalone" reader |
| 247 |
(processes standalone text file documents) was completed in February, |
| 248 |
and a basic HTML writer (producing HTML 4.01, using CSS-1) was |
| 249 |
completed in early March. |
| 250 |
|
| 251 |
`PEP 287`_, "reStructuredText Standard Docstring Format", was created |
| 252 |
to formally propose reStructuredText as a standard format for Python |
| 253 |
docstrings, PEPs, and other files. It was first posted to |
| 254 |
comp.lang.python_ and the Python-dev_ mailing list on 2002-04-02. |
| 255 |
|
| 256 |
Version 0.4 of the reStructuredText__ and `Docstring Processing |
| 257 |
System`_ projects were released in April 2002. The two projects were |
| 258 |
immediately merged, renamed to "Docutils_", and a 0.1 release soon |
| 259 |
followed. |
| 260 |
|
| 261 |
.. __: `reStructuredText SourceForge project`_ |
| 262 |
|
| 263 |
.. [#spec-2] The second draft of the spec: |
| 264 |
|
| 265 |
- `An Introduction to reStructuredText`__ |
| 266 |
- `Problems With StructuredText`__ |
| 267 |
- `reStructuredText Markup Specification`__ |
| 268 |
- `Python Extensions to the reStructuredText Markup |
| 269 |
Specification`__ |
| 270 |
|
| 271 |
__ https://mail.python.org/pipermail/doc-sig/2001-June/001858.html |
| 272 |
__ https://mail.python.org/pipermail/doc-sig/2001-June/001859.html |
| 273 |
__ https://mail.python.org/pipermail/doc-sig/2001-June/001860.html |
| 274 |
__ https://mail.python.org/pipermail/doc-sig/2001-June/001861.html |
| 275 |
|
| 276 |
.. [#peps-1] First drafts of the PEPs: |
| 277 |
|
| 278 |
- `PEP 256: Docstring Processing System Framework`__ |
| 279 |
- `PEP 258: DPS Generic Implementation Details`__ |
| 280 |
- `PEP 257: Docstring Conventions`__ |
| 281 |
|
| 282 |
Current working versions of the PEPs can be found in |
| 283 |
https://docutils.sourceforge.io/docs/peps/, and official versions |
| 284 |
can be found in the `master PEP repository`_. |
| 285 |
|
| 286 |
__ https://mail.python.org/pipermail/doc-sig/2001-June/001855.html |
| 287 |
__ https://mail.python.org/pipermail/doc-sig/2001-June/001856.html |
| 288 |
__ https://mail.python.org/pipermail/doc-sig/2001-June/001857.html |
| 289 |
|
| 290 |
|
| 291 |
.. _Zope Corporation: http://www.zope.com |
| 292 |
.. _ZOPE: https://www.zope.dev |
| 293 |
.. _reStructuredText SourceForge project: |
| 294 |
http://structuredtext.sourceforge.net/ |
| 295 |
.. _pythondoc: http://starship.python.net/crew/danilo/pythondoc/ |
| 296 |
.. _project history file: ../../../HISTORY.html |
| 297 |
.. _PEP 287: ../../peps/pep-0287.html |
| 298 |
.. _Docstring Processing System framework: ../../peps/pep-0256.html |
| 299 |
.. _comp.lang.python: news:comp.lang.python |
| 300 |
.. _Python-dev: https://mail.python.org/pipermail/python-dev/ |
| 301 |
.. _Docstring Processing System: http://docstring.sourceforge.net/ |
| 302 |
.. _master PEP repository: https://www.python.org/dev/peps/ |
| 303 |
|
| 304 |
|
| 305 |
.. |
| 306 |
Local Variables: |
| 307 |
mode: indented-text |
| 308 |
indent-tabs-mode: nil |
| 309 |
sentence-end-double-space: t |
| 310 |
fill-column: 70 |
| 311 |
End: |