1 .. include:: docs/header0.rst
3 .. NOTE TO MAINTAINERS: Please add new questions to the end of their
4 sections, so section/question numbers remain stable.
6 ===========================================
7 Docutils FAQ (Frequently Asked Questions)
8 ===========================================
12 :Web site: https://docutils.sourceforge.io/
13 :Copyright: This document has been placed in the public domain.
19 This is a work in progress. If you are reading a local copy, the
20 `master copy`_ might be newer. This document uses relative links;
21 if they don't work, please use the master copy.
23 Please feel free to ask questions and/or provide answers; send email
24 to the `Docutils-users`_ mailing list. Project members should feel
25 free to edit the source text file directly.
27 .. _master copy: https://docutils.sourceforge.io/FAQ.html
29 .. _Docutils-users: docs/user/mailing-lists.html#docutils-users
39 Docutils_ is a system for processing plaintext documentation into
40 useful formats, such as HTML, XML, and LaTeX. It supports multiple
41 types of input, such as standalone files, `PEPs (Python Enhancement
42 Proposals)`_, and string input. Client code may add other input types,
43 e.g. Sphinx_ comes with an extension to extract inline documentation
44 from Python modules and packages.
46 The Docutils distribution consists of:
48 * a library (the "docutils" package), which `can be used by client
50 * several `front-end tools`_ (such as ``rst2html``, which converts
51 reStructuredText input into HTML output);
52 * a `test suite`_; and
55 For an overview of the Docutils project implementation,
56 see :PEP:`258`, "Docutils Design Specification".
58 Docutils is implemented in Python_.
60 .. _Docutils: https://docutils.sourceforge.io/
61 .. _PEPs (Python Enhancement Proposals):
62 https://peps.python.org/pep-0012
63 .. _can be used by client code: docs/api/publisher.html
64 .. _front-end tools: docs/user/tools.html
65 .. _test suite: docs/dev/testing.html
66 .. _documentation: docs/index.html
67 .. _Python: https://www.python.org/
70 Why is it called "Docutils"?
71 ----------------------------
73 Docutils is short for "Python Documentation Utilities". The name
74 "Docutils" was inspired by "Distutils", the Python Distribution
75 Utilities architected by Greg Ward, a component of Python's standard
78 The earliest known use of the term "docutils" in a Python context was
79 a `fleeting reference`__ in a message by Fred Drake on 1999-12-02 in
80 the Python Doc-SIG mailing list. It was suggested `as a project
81 name`__ on 2000-11-27 on Doc-SIG, again by Fred Drake, in response to
82 a question from Tony "Tibs" Ibbs: "What do we want to *call* this
83 thing?". This was shortly after David Goodger first `announced
84 reStructuredText`__ on Doc-SIG.
86 Tibs used the name "Docutils" for `his effort`__ "to document what the
87 Python docutils package should support, with a particular emphasis on
88 documentation strings". Tibs joined the current project (and its
89 predecessors) and graciously donated the name.
91 For more history of reStructuredText and the Docutils project, see `An
92 Introduction to reStructuredText`_.
94 Please note that the name is "Docutils", not "DocUtils" or "Doc-Utils"
95 or any other variation. It is pronounced as in "DOCumentation
96 UTILitieS", with emphasis on the first syllable.
98 .. _An Introduction to reStructuredText: docs/ref/rst/introduction.html
99 __ https://mail.python.org/pipermail/doc-sig/1999-December/000878.html
100 __ https://mail.python.org/pipermail/doc-sig/2000-November/001252.html
101 __ https://mail.python.org/pipermail/doc-sig/2000-November/001239.html
102 __ http://homepage.ntlworld.com/tibsnjoan/docutils/STpy.html
105 Is there a GUI authoring environment for Docutils?
106 --------------------------------------------------
108 See the links to editors_ supporting reStructuredText.
110 .. _editors: docs/user/links.html#editors
113 What is the status of the Docutils project?
114 -------------------------------------------
116 Docutils is mainly stable, with documented APIs and architecture
117 subject to change after announcement and a transition period.
119 We fix bugs as they are reported. This means the code from the
120 repository_ (or the snapshots_) is the most stable as well as the most
121 featureful most of the time.
124 What is the Docutils project release policy?
125 --------------------------------------------
127 Besides the regular releases_, we provide automatically-generated
128 snapshots_ which always contain the latest code from the repository_.
129 As the project matures, we may formalize on a
130 stable/development-branch scheme, but we're not using anything like
133 .. _releases: https://pypi.org/project/docutils/#history
134 .. _snapshots: https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/
135 .. _repository: docs/dev/repository.html
138 How can I get a new feature into Docutils?
139 ------------------------------------------
141 * Present your idea at the docutils-develop_ mailing list or file a
142 ticket at Docutils' `feature request tracker`_.
143 Convince the Docutils developers that this is a valuable addition.
147 * Be patient, and be persistent. None of us are paid to do this,
148 it's all in our spare time, which is precious and rare.
150 .. _docutils-develop: docs/user/mailing-lists.html#docutils-develop
151 .. _extensions and related projects:
152 docs/dev/policies.html#extensions-and-related-projects
153 .. _feature request tracker:
154 https://sourceforge.net/p/docutils/feature-requests/
160 What is reStructuredText?
161 -------------------------
163 reStructuredText_ is an easy-to-read, what-you-see-is-what-you-get
164 plaintext markup syntax and parser system. The reStructuredText
165 parser is a component of Docutils_. reStructuredText is a revision
166 and reinterpretation of the StructuredText_ and Setext_ lightweight
169 If you are reading this on the web, you can see for yourself. `The
170 source for this FAQ <FAQ.rst>`_ is written in reStructuredText; open
171 it in another window and compare them side by side.
173 `A ReStructuredText Primer`_ and the `Quick reStructuredText`_ user
174 reference are a good place to start. The `reStructuredText Markup
175 Specification`_ is a detailed technical specification.
177 .. _A ReStructuredText Primer: docs/user/rst/quickstart.html
178 .. _Quick reStructuredText: docs/user/rst/quickref.html
179 .. _reStructuredText Markup Specification:
180 docs/ref/rst/restructuredtext.html
181 .. _reStructuredText: https://docutils.sourceforge.io/rst.html
183 http://dev.zope.org/Members/jim/StructuredTextWiki/FrontPage/
184 .. _Setext: https://docutils.sourceforge.io/mirror/setext.html
187 Why is it called "reStructuredText"?
188 ------------------------------------
190 The name came from a combination of "StructuredText", one of
191 reStructuredText's predecessors, with "re": "revised", "reworked", and
192 "reinterpreted", and as in the ``re.py`` regular expression module.
193 For a detailed history of reStructuredText and the Docutils project,
194 see `An Introduction to reStructuredText`_.
196 "reStructuredText" is **ONE** word, *not two!*
199 What's the standard abbreviation for "reStructuredText"?
200 --------------------------------------------------------
202 "RST" (or "rST") and "ReST" (or "reST") are both acceptable.
203 Care should be taken with capitalization, to avoid confusion with
204 "REST__", an acronym for "Representational State Transfer".
206 __ https://en.wikipedia.org/wiki/Representational_State_Transfer
209 What's the standard filename extension for a reStructuredText file?
210 -------------------------------------------------------------------
212 The most commonly used extensions are ".rst" and ".txt".
214 Also see `What's the official MIME type for reStructuredText data?`_
217 Are there any reStructuredText editor extensions?
218 -------------------------------------------------
220 See the list of editors_ supporting reStructuredText.
223 How can I indicate the document title? Subtitle?
224 -------------------------------------------------
226 A uniquely-adorned section title at the beginning of a document is
227 treated specially, as the document title. Similarly, a
228 uniquely-adorned section title immediately after the document title
229 becomes the document subtitle. For example::
231 This is the Document Title
232 ==========================
234 This is the Document Subtitle
235 -----------------------------
237 Here's an ordinary paragraph.
239 See also `A reStructuredText Primer`__
240 and the `reStructuredText Markup Specification`__.
242 __ docs/user/rst/quickstart.html#document-title-subtitle
243 __ docs/ref/rst/restructuredtext.html#document-title
245 How can I represent esoteric characters (e.g. character entities) in a document?
246 --------------------------------------------------------------------------------
248 For example, say you want an em-dash (XML character entity —,
249 Unicode character U+2014) in your document.
251 ReStructuredText has no character entity subsystem. [#]_
252 However, Docutils uses Unicode so you use a literal character
253 (e.g. a "real" em-dash) for all charactes supported by the
254 `input encoding`_ (by default "UTF-8").
256 If you are restricted to 7-bit ASCII or a legacy encoding,
257 there is a workaround:
258 `Standard Substitution Definition Sets`_ provide equivalents of
259 XML & HTML character entity sets as substitution definitions. [#]_
260 For example, the Japanese yen currency symbol can be used as follows::
262 .. include:: <xhtml1-lat1.txt>
264 |yen| 600 for a complete meal? That's cheap!
266 You can also create custom `substitution definitions`_ in your document
267 using the "unicode_" directive, e.g.::
269 .. |--| unicode:: U+2013 .. en dash
270 .. |---| unicode:: U+2014 .. em dash, trimming surrounding whitespace
273 .. |--| unicode:: U+2013 .. en dash
274 .. |---| unicode:: U+2014 .. em dash, trimming surrounding whitespace
277 Now you can write dashes using pure ASCII: "``foo |--| bar; foo |---|
278 bar``", rendered as "foo |--| bar; foo |---| bar".
279 The ``:trim:`` option for
280 the em dash is necessary because you cannot write "``foo|---|bar``";
281 thus you need to add spaces ("``foo |---| bar``") and advise the
282 reStructuredText parser to trim the spaces.
284 .. [#] reStructuredText doesn't know anything about XML character
285 entities. To Docutils, "—" in input text is 7 discrete
286 characters; no interpretation happens. When writing HTML, the
287 "&" is converted to "``&``", so in the raw output you'd see
288 "``&mdash;``" and in the HTML browser "—".
290 .. [#] Thanks to David Priest for the original idea.
292 .. _input encoding: docs/user/config.html#input-encoding
293 .. _Standard Substitution Definition Sets: docs/ref/rst/definitions.html
294 .. _substitution definitions: docs/ref/rst/restructuredtext.html
295 #substitution-definitions
296 .. _unicode: docs/ref/rst/directives.html#unicode-character-codes
299 How can I generate backticks using a Scandinavian keyboard?
300 -----------------------------------------------------------
302 The use of backticks in reStructuredText is a bit awkward with
303 Scandinavian keyboards, where the backtick is a "dead" key. To get
304 one ` character one must press SHIFT-` + SPACE.
306 Unfortunately, with all the variations out there, there's no way to
307 please everyone. For Scandinavian programmers and technical writers,
308 this is not limited to reStructuredText but affects many languages and
311 Possible solutions include
313 * If you have to input a lot of backticks, simply type one in the
314 normal/awkward way, select it, copy and then paste the rest (CTRL-V
315 is a lot faster than SHIFT-` + SPACE).
317 * Use keyboard macros.
319 * Remap the keyboard. The Scandinavian keyboard layout is awkward for
320 other programming/technical characters too; for example, []{}
321 etc. are a bit awkward compared to US keyboards.
323 According to Axel Kollmorgen,
325 Under Windows, you can use the `Microsoft Keyboard Layout Creator
326 <http://www.microsoft.com/globaldev/tools/msklc.mspx>`__ to easily
327 map the backtick key to a real backtick (no dead key). took me
328 five minutes to load my default (german) keyboard layout, untick
329 "Dead Key?" from the backtick key properties ("in all shift
330 states"), "build dll and setup package", install the generated
331 .msi, and add my custom keyboard layout via Control Panel >
332 Regional and Language Options > Languages > Details > Add
333 Keyboard layout (and setting it as default "when you start your
336 * Use a virtual/screen keyboard or character palette, such as:
338 - `Web-based keyboards <http://keyboard.lab.co.il/>`__ (IE only
340 - Windows: `Click-N-Type <http://www.lakefolks.org/cnt/>`__.
341 - Mac OS X: the Character Palette can store a set of favorite
342 characters for easy input. Open System Preferences,
343 International, Input Menu tab, enable "Show input menu in menu
344 bar", and be sure that Character Palette is enabled in the list.
346 If anyone knows of other/better solutions, please `let us know`_.
349 Are there any tools for HTML/XML-to-reStructuredText? (Round-tripping)
350 -----------------------------------------------------------------------
352 People have tossed the idea around, and some implementations of
353 reStructuredText-generating tools can be found in the `Docutils Links`_.
355 There's no reason why reStructuredText should not be round-trippable
356 to/from XML; any technicalities which prevent round-tripping would be
357 considered bugs. Whitespace would not be identical, but paragraphs
358 shouldn't suffer. The tricky parts would be the smaller details, like
359 links and IDs and other bookkeeping.
361 For HTML, true round-tripping may not be possible. Even adding lots
362 of extra "class" attributes may not be enough. A "simple HTML" to RST
363 filter is possible -- for some definition of "simple HTML" -- but HTML
364 is used as dumb formatting so much that such a filter may not be
365 particularly useful. An 80/20 approach should work though: build a
366 tool that does 80% of the work automatically, leaving the other 20%
369 .. _Docutils Link List:
370 .. _Docutils Links: docs/user/links.html
373 Are there any Wikis that use reStructuredText syntax?
374 -----------------------------------------------------
376 Yes, see `Wikis`__ in the `Docutils Links`_.
378 __ docs/user/links.html#wikis
382 Are there any Weblog (Blog) projects that use reStructuredText syntax?
383 ----------------------------------------------------------------------
385 With no implied endorsement or recommendation, and in no particular
388 * `Firedrop <http://www.voidspace.org.uk/python/firedrop2/>`__
389 * `PyBloxsom <http://pyblosxom.github.io/>`__
390 * `Lino WebMan <http://lino.sourceforge.net/webman.html>`__
391 * `Pelican <http://blog.getpelican.com/>`__
392 (also listed `on PyPi <http://pypi.python.org/pypi/pelican>`__)
394 Please `let us know`_ of any other reStructuredText Blogs.
397 .. _Can lists be indented without generating block quotes?:
399 How should I mark up lists?
400 ---------------------------
402 Bullet_ & enumerated_ list markup is very intuitive but there are 2
403 points that must be noted:
405 .. _bullet: docs/ref/rst/restructuredtext.html#bullet-lists
406 .. _enumerated: docs/ref/rst/restructuredtext.html#enumerated-lists
408 1. Lists should **not** be indented. This is correct::
419 while this is probably incorrect::
430 The extra indentation (of the list containing items 1.1 and 1.2) is
431 recognized as a block quote. This is usually not what you mean and
432 it causes the list in the output to be indented too much.
434 2. There **must** be blank lines around list items, except between
435 items of the same level, where blank lines are optional. The
436 example above shows this.
438 Note that formatting of the *output* is independent of the input, and
439 is decided by the writer and the stylesheet. For instance, lists
440 *are* indented in HTML output by default. See `How are lists
441 formatted in HTML?`_ for details.
444 Could lists be indented without generating block quotes?
445 --------------------------------------------------------
447 Some people like to write lists with indentation but don't intend a
448 blockquote context. There has been a lot of discussion about allowing
449 this in reStructuredText, but there are some issues that would need to
450 be resolved before it could be implemented. There is a summary of the
451 issues and pointers to the discussions in `the to-do list`__.
453 __ docs/dev/todo.html#indented-lists
456 Could the requirement for blank lines around lists be relaxed?
457 --------------------------------------------------------------
461 In reStructuredText, it would be impossible to unambiguously mark up
462 and parse lists without blank lines before and after. Deeply nested
463 lists may look ugly with so many blank lines, but it's a price we pay
464 for unambiguous markup. Some other plaintext markup systems do not
465 require blank lines in nested lists, but they have to compromise
466 somehow, either accepting ambiguity or requiring extra complexity.
467 For example, `Epytext <http://epydoc.sourceforge.net/epytext.html#list>`__ does
468 not require blank lines around lists, but it does require that lists
469 be indented and that ambiguous cases be escaped.
472 How can I include mathematical equations in documents?
473 ------------------------------------------------------
475 Use `LaTeX math syntax`_ in a `math directive`_ or `math role`_.
477 .. _LaTeX math syntax: docs/ref/rst/mathematics.html
478 .. _math directive: docs/ref/rst/directives.html#math
479 .. _math role: docs/ref/rst/roles.html#math
482 Is nested inline markup possible?
483 ---------------------------------
485 Not currently, no. It's on the `to-do list`__ (`details here`__), and
486 hopefully will be part of the reStructuredText parser soon. At that
487 time, markup like this will become possible::
489 Here is some *emphasized text containing a `hyperlink`_ and
490 ``inline literals``*.
492 __ docs/dev/todo.html#nested-inline-markup
493 __ docs/dev/rst/alternatives.html#nested-inline-markup
495 There are workarounds, but they are either convoluted or ugly or both.
496 They are not recommended.
498 * Inline markup can be combined with hyperlinks using `substitution
499 definitions`__ and references__ with the `"replace" directive`__.
502 Here is an |emphasized hyperlink|_.
504 .. |emphasized hyperlink| replace:: *emphasized hyperlink*
505 .. _emphasized hyperlink: https://example.org
507 It is not possible for just a portion of the replacement text to be
508 a hyperlink; it's the entire replacement text or nothing.
510 __ docs/ref/rst/restructuredtext.html#substitution-definitions
511 __ docs/ref/rst/restructuredtext.html#substitution-references
512 __ docs/ref/rst/directives.html#replace
514 * The `"raw" directive`__ can be used to insert raw HTML into HTML
517 Here is some |stuff|.
519 .. |stuff| raw:: html
521 <em>emphasized text containing a
522 <a href="https://example.org">hyperlink</a> and
523 <tt>inline literals</tt></em>
525 Raw LaTeX is supported for LaTeX output, etc.
527 __ docs/ref/rst/directives.html#raw
530 How to indicate a line break or a significant newline?
531 ------------------------------------------------------
533 `Line blocks`__ are designed for address blocks, verse, and other
534 cases where line breaks are significant and must be preserved. Unlike
535 literal blocks, the typeface is not changed, and inline markup is
536 recognized. For example::
538 | A one, two, a one two three four
540 | Half a bee, philosophically,
541 | must, *ipso facto*, half not be.
542 | But half the bee has got to be,
543 | *vis a vis* its entity. D'you see?
545 | But can a bee be said to be
546 | or not to be an entire bee,
547 | when half the bee is not a bee,
548 | due to some ancient injury?
552 __ docs/ref/rst/restructuredtext.html#line-blocks
554 Here's a workaround for manually inserting explicit line breaks in
561 I want to break this line here: |br| this is after the break.
563 If the extra whitespace bothers you, |br|\ backslash-escape it.
566 A URL containing asterisks doesn't work. What to do?
567 -----------------------------------------------------
569 Asterisks are valid URL characters (see :RFC:`2396`), sometimes used
570 in URLs. For example::
572 http://cvs.example.org/viewcvs.py/*checkout*/module/file
574 Unfortunately, the parser thinks the asterisks are indicating
575 emphasis. The slashes serve as delineating punctuation, allowing the
576 asterisks to be recognized as markup. The example above is separated
577 by the parser into a truncated URL, an emphasized word, and some
580 http://cvs.example.org/viewcvs.py/
584 To turn off markup recognition, use a backslash to escape at least the
585 first asterisk, like this::
587 http://cvs.example.org/viewcvs.py/\*checkout*/module/file
589 Escaping the second asterisk doesn't hurt, but it isn't necessary.
592 How can I make a literal block with *some* formatting?
593 ------------------------------------------------------
595 Use the `parsed-literal`_ directive.
597 .. _parsed-literal: docs/ref/rst/directives.html#parsed-literal
599 Scenario: a document contains some source code, which calls for a
600 literal block to preserve linebreaks and whitespace. But part of the
601 source code should be formatted, for example as emphasis or as a
602 hyperlink. This calls for a *parsed* literal block::
606 print "Hello world!" # *tricky* code [1]_
608 The emphasis (``*tricky*``) and footnote reference (``[1]_``) will be
612 Can reStructuredText be used for web or generic templating?
613 -----------------------------------------------------------
615 Docutils and reStructuredText can be used with or as a component of a
616 templating system, but they do not themselves include templating
617 functionality. Templating should simply be left to dedicated
618 templating systems. Users can choose a templating system to apply to
619 their reStructuredText documents as best serves their interests.
621 There are many good templating systems for Python (ht2html_, YAPTU_,
622 Quixote_'s PTL, Cheetah_, etc.; see this non-exhaustive list of `some
623 other templating systems`_), and many more for other languages, each
624 with different approaches. We invite you to try several and find one
625 you like. If you adapt it to use Docutils/reStructuredText, please
626 consider contributing the code to Docutils or `let us know`_ and we'll
629 One reST-specific web templating system is `rest2web
630 <http://www.voidspace.org.uk/python/rest2web>`_, a tool for
631 automatically building websites, or parts of websites.
633 .. _ht2html: http://ht2html.sourceforge.net/
635 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305
636 .. _Quixote: http://www.mems-exchange.org/software/quixote/
637 .. _Cheetah: http://www.cheetahtemplate.org/
638 .. _some other templating systems:
639 http://webware.sourceforge.net/Papers/Templates/
642 How can I mark up a FAQ or other list of questions & answers?
643 -------------------------------------------------------------
645 There is no specific syntax for FAQs and Q&A lists. Here are two
648 1. For a FAQ (Frequently Asked Questions, usually with answers), a
649 convenient way to mark up the questions is as section titles, with
650 the answer(s) as section content. This document is marked up in
653 The advantages of using section titles for questions are: sections
654 can be numbered automatically, and a table of contents can be
655 generated automatically. One limitation of this format is that
656 questions must fit on one line (section titles may not wrap, in the
657 source text). For very long questions, the title may be a summary
658 of the question, with the full question in the section body.
660 2. Field lists work well as Q&A lists::
662 :Q: What kind of questions can we
665 :A: Any kind we like!
667 In order to separate questions, lists can be used:
669 1. :Q: What kind of question can we
671 :A: Any kind we like!
673 2. :Q: How many answers can a question have?
676 :A3: Answers can be numbered like this.
680 If you don't want to number or otherwise mark questions, you can
681 use an empty comment between individual field lists to separate
695 Can I produce documents in right-to-left languages?
696 ---------------------------------------------------
698 Languages written from right to left, such as Arabic and Hebrew, must
699 be reordered according to the `Unicode Bidi Algorithm`_. This
700 requires support from the editor and special markup in the output
703 The source format of reStructuredText is relatively bidi-friendly:
704 most constructs are denoted by punctuation without intrusion of
705 English and when you must write in English, it's usually on a separate
706 line. So any editor that auto-detects direction per-line (like gedit
707 or geresh_) will suffice.
709 Moreover, it's possible to translate_ all reStructuredText keywords.
710 Docutils 0.17 includes translations for Arab, Hebrew, and
711 Persian/Farsi. This should allow reasonable use of editors limited to
712 a single base direction for the whole document (like Notepad, Vim and
713 text boxes in Firefox).
715 .. _Unicode Bidi Algorithm: https://www.unicode.org/reports/tr9/
716 .. _geresh: http://www.typo.co.il/~mooffie/geresh/
717 .. _translate: docs/howto/i18n.html
719 The second problem is bidi markup of the output. There is an almost
720 transparent implicit solution for HTML:
722 * Grab http://cben-hacks.sourceforge.net/bidi/hibidi.py and
723 http://cben-hacks.sourceforge.net/bidi/rst2html_hibidi.py.
724 Put them both in the same directory and make them executable.
726 * Use ``rst2html_hibidi.py`` instead of ``rst2html``.
728 * It infers dir attributes in the HTML from the text. It does it
729 hierachically, giving much better results than usual. You can still
730 use LRM/RLM and LRE/RLE/PDF control codes to help it.
732 * If you want the gory details: See the full theory_, and note the
733 incomplete practice_ (this is still a partial implementation - but
734 sufficient for most needs).
736 .. _theory: http://cben-hacks.sourceforge.net/bidi/hibidi.html
737 .. _practice: http://cben-hacks.sourceforge.net/bidi/hibidi.html#practice
739 There is also an explicit way to set directions through CSS and
742 * Copy ``default.css`` to a new file and add relevant parts of the
745 /* Use these two if the main document direction is RTL */
746 body { direction: rtl; }
747 div.sidebar { float: left !important; }
749 /* The next 3 rules are very useful in documents containing pieces
750 of code in english */
751 /* Use this if you all your literal blocks (::) are LTR */
752 pre {direction: ltr; unicode-bidi: embed; }
753 /* Use this if you all your inline literals (``) are LTR */
754 tt {direction: ltr; unicode-bidi: embed; }
755 /* Use this if you all your interpreted text (`) is LTR */
756 cite {direction: ltr; unicode-bidi: embed; }
758 /* Allow manual direction override by class directive and roles */
759 .rtl { direction: rtl; }
760 .ltr { direction: ltr; }
762 * Select this new stylesheet with ``--stylesheet=<file>`` or the
765 * Now if you need to override the direction of some element (from a
766 paragraph to a whole section), write::
774 before it (see the class_ directive for details).
776 * To change the direction of some inline text fragment, you can use
777 RLE/LRE/PDF control characters, or write ``:rtl:`RTL text``` /
778 ``:ltr:`RTL text```. To use the latter syntax, you must write this
779 once at the beginning of your document::
784 .. _stylesheet: docs/user/config.html#stylesheet
785 .. _class: docs/ref/rst/directives.rst#class
787 LaTeX is quite hard to implement (it doesn't support the bidi
788 algorithm, so all direction changes - even numbers in RTL text - must
789 be explicitly marked). Other formats are more-or-less easy.
791 If you have any questions/problems/bugs related to bidi with docutils,
792 ask `Beni Cherniavsky`__ directly or the `Docutils-users`_ mailing
795 __ mailto:cben@users.sf.net
798 What's the official MIME type for reStructuredText data?
799 --------------------------------------------------------
801 While there is no registered MIME type for reStructuredText, the
802 "official unofficial" standard MIME type is "text/x-rst". [#]_ This was
803 invented for the build system for PEPs (Python Enhancement Proposals),
804 and it's used by the python.org web site build system.
806 Also see `What's the standard filename extension for a
807 reStructuredText file?`_
809 .. [#] The "x-" prefix means it's an unregistered MIME type.
812 How can I mark up a TODO list?
813 ------------------------------
815 You may use a field list with class argument and some CSS styling.
816 For an example see `Docutils TODO lists`_ and its source todo-lists.rst_.
818 .. _Docutils TODO lists: docs/user/todo-lists.html
819 .. _todo-lists.rst: docs/user/todo-lists.rst
822 How can I specify an image grid?
823 --------------------------------
825 In order to arrange images (or other content) in a grid,
826 a borderless `list table`_ can be used. For example::
831 * - .. image:: rst/images/title-scaling.svg
832 - .. image:: rst/images/biohazard.svg
833 * - .. image:: rst/images/biohazard.svg
834 - .. image:: rst/images/biohazard.svg
836 Use figures, if you want also captions::
841 * - .. figure:: rst/images/title-scaling.svg
845 - .. figure:: rst/images/biohazard.svg
849 .. _list table: docs/ref/rst/directives.html#list-table
855 What is the status of the HTML Writer?
856 --------------------------------------
858 The default HTML Writer module, `html4css1`_, is
859 a proof-of-concept reference implementation. While it is a complete
860 implementation, some aspects of the HTML it produces may be outdated or
861 incompatible with older browsers or specialized applications (such as
864 The `html5 writer`_ generates semantic HTML output compatible with HTML5.
865 For the full selection see `Docutils HTML writers`_
867 .. _html4css1: docs/user/html.html#html4css1
868 .. _HTML5 writer: docs/user/html.html#html5
869 .. _Docutils HTML writers: docs/user/html.html
872 What browsers are supported?
873 ----------------------------
875 No specific browser is targeted; all modern graphical browsers should
876 work. Some older browsers, text-only browsers, and browsers without
877 full CSS support are known to produce inferior results. Firefox,
878 Safari, Opera, Chrome, Edge, and MS Internet Explorer (version 5.0 and up)
879 are known to give good results. Reports of experiences with other
880 browsers are welcome.
883 Unexpected results from ``rst2html``: H1, H1 instead of H1, H2. Why?
884 --------------------------------------------------------------------------
886 This only regards output from the `html4css1`_ writer and is configurable
887 via the initial_header_level_ setting.
892 Here's the question in full:
899 All my life, I wanted to be H1.
904 But along came H1, and so shouldn't I be H2?
910 Yeah, imagine me, I'm stuck at H3! No?!?
912 When I run it through ``rst2html4``, I get unexpected results
913 (below). I was expecting H1, H2, then H3; instead, I get H1, H1,
920 <title>Heading 1</title>
923 <div class="document" id="heading-1">
924 <h1 class="title">Heading 1</h1> <-- first H1
925 <p>All my life, I wanted to be H1.</p>
926 <div class="section" id="heading-1-1">
927 <h1><a name="heading-1-1">Heading 1.1</a></h1> <-- H1
928 <p>But along came H1, and so now I must be H2.</p>
929 <div class="section" id="heading-1-1-1">
930 <h2><a name="heading-1-1-1">Heading 1.1.1</a></h2>
931 <p>Yeah, imagine me, I'm stuck at H3!</p>
936 Check the "class" attribute on the H1 tags, and you will see a
937 difference. The first H1 is actually ``<h1 class="title">``; this is
938 the document title, and the default stylesheet renders it centered.
939 There can also be an ``<h2 class="subtitle">`` for the document
942 If there's only one highest-level section title at the beginning of a
943 document, it is treated specially, as the document title. (Similarly, a
944 lone second-highest-level section title may become the document
945 subtitle.) See `How can I indicate the document title? Subtitle?`_ for
946 details. Rather than use a plain H1 for the document title, we use ``<h1
947 class="title">`` so that we can use H1 again within the document. Why
948 do we do this? HTML only has H1-H6, so by making H1 do double duty, we
949 effectively reserve these tags to provide 6 levels of heading beyond the
950 single document title.
952 With "html4css1", HTML is being used for dumb formatting for nothing
953 but final display. A stylesheet *is required*, and one is provided;
954 see `Docutils HTML writers`_. Of course, you're
955 welcome to roll your own. The default stylesheet provides rules to
956 format ``<h1 class="title">`` and ``<h2 class="subtitle">``
957 differently from ordinary ``<h1>`` and ``<h2>``::
965 If you don't want the top section heading to be interpreted as a
966 title at all, disable the `doctitle_xform`_ setting
967 (``--no-doc-title`` option). This will interpret your document
968 differently from the standard settings, which might not be a good
969 idea. If you don't like the reuse of the H1 in the HTML output, you
970 can tweak the `initial_header_level`_ setting
971 (``--initial-header-level`` option) -- but unless you match its value
972 to your specific document, you might end up with bad HTML (e.g. H3
975 .. _doctitle_xform: docs/user/config.html#doctitle-xform
976 .. _initial_header_level: docs/user/config.html#initial-header-level
978 (Thanks to Mark McEahern for the question and much of the answer.)
980 .. note:: For the `html5 writer`_, `initial_header_level`_ defaults to
981 ``2`` because this is what the `HTML5 standard`__ expects as
982 start value for headings nested in <section> elements.
984 .. Sectioning content elements are always considered subsections of
985 their nearest ancestor *sectioning root* [#]_ or their nearest
986 ancestor element of *sectioning content* [#]_, whichever is nearest,
989 .. [#] <blockquote>, <body>, <details>, <dialog>, <fieldset>,
991 .. [#] <article>, <aside>, <nav>, <section>
993 I.e., a top-level <section> is a subsection of <body>.
995 __ https://www.w3.org/TR/html53/sections.html#headings-and-sections
998 How are lists formatted in HTML?
999 --------------------------------
1001 If list formatting looks strange, first check that you understand
1004 __ `How should I mark up lists?`_
1006 * By default, HTML browsers indent lists relative to their context.
1007 This follows a long tradition in browsers (but isn't so established
1008 in print). If you don't like it, you should change the stylesheet.
1010 This is different from how lists look in reStructuredText source.
1011 Extra indentation in the source indicates a blockquote, resulting in
1012 too much indentation in the browser.
1014 * A list item can contain multiple paragraphs etc. In complex cases
1015 list items are separated by vertical space. By default this spacing
1016 is omitted in "simple" lists. A list is simple if every item
1017 contains a simple paragraph and/or a "simple" nested list. For
1029 text after a nested list
1035 In this example the nested lists are simple (and should appear
1036 compacted) but the outer list is not.
1038 If you want all lists to have equal spacing, disable the
1039 `compact_lists`_ setting (``--no-compact-lists`` option). The
1040 precise spacing can be controlled in the stylesheet.
1042 Note again that this is not exactly WYSIWYG: it partially resembles
1043 the rules about blank lines being optional between list items in
1044 reStructuredText -- but adding/removing optional blank lines does
1045 not affect spacing in the output! It's a feature, not a bug: you
1046 write it as you like but the output is styled consistently.
1048 .. _compact_lists: docs/user/config.html#compact-lists
1051 Why do enumerated lists only use numbers (no letters or roman numerals)?
1052 ------------------------------------------------------------------------
1054 In HTML, the rendering of enumerators (the numbers or letters acting as
1055 list markers) is completely governed by the stylesheet, so either the
1056 browser can't find the stylesheet (try enabling the
1057 `embed_stylesheet`_ setting [``--embed-stylesheet`` option]), or the
1058 browser can't understand it (try a not too old Firefox, Chrome, Opera,
1059 Safari, Edge, or even MSIE).
1061 .. _embed_stylesheet: docs/user/config.html#embed-stylesheet
1064 There appear to be garbage characters in the HTML. What's up?
1065 --------------------------------------------------------------
1067 What you're seeing is most probably not garbage, but the result of a
1068 mismatch between the actual encoding of the HTML output and the
1069 encoding your browser is expecting. Your browser is misinterpreting
1070 the HTML data, which is encoded text. A discussion of text encodings
1071 is beyond the scope of this FAQ; see one or more of these documents
1074 * `UTF-8 and Unicode FAQ for Unix/Linux
1075 <http://www.cl.cam.ac.uk/~mgk25/unicode.html>`_
1077 * Chapters 3 and 4 of `Introduction to i18n [Internationalization]
1078 <http://www.debian.org/doc/manuals/intro-i18n/>`_
1080 * `Python Unicode Tutorial
1081 <http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
1083 The common case is with the default output encoding (UTF-8), when
1084 using symbol-footnotes. Most footnote symbols are not available in ASCII.
1085 When encoded with UTF-8 and viewed with ordinary ASCII tools,
1086 these characters will appear to be multi-character garbage.
1088 You may have an decoding problem in your browser (or editor, etc.).
1089 The encoding of the output is set to UTF-8, but your browser isn't
1090 recognizing that. You can either try to fix your browser (enable
1091 "UTF-8 character set", sometimes called "Unicode"), or choose a
1092 different `output-encoding`_. You can also try
1093 ``--output-encoding=ascii:xmlcharrefreplace`` for HTML or XML, but not
1094 applicable to non-XMLish outputs.
1096 If you're generating document fragments, the "Content-Type" metadata
1097 (between the HTML ``<head>`` and ``</head>`` tags) must agree with the
1098 encoding of the rest of the document. For UTF-8, it should be::
1100 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1102 Also, Docutils normally generates an XML declaration as the first line
1103 of the output. It must also match the document encoding. For UTF-8::
1105 <?xml version="1.0" encoding="utf-8" ?>
1107 .. _sectnum: docs/ref/rst/directives.html#sectnum
1108 .. _output-encoding: docs/user/config.html#output-encoding
1111 How can I retrieve the body of the HTML document?
1112 -------------------------------------------------
1114 (This is usually needed when using Docutils in conjunction with a
1117 You can use the `docutils.core.publish_parts()`_ function, which
1118 returns a dictionary containing an 'html_body_' entry.
1120 .. _docutils.core.publish_parts(): docs/api/publisher.html#publish-parts
1121 .. _html_body: docs/api/publisher.html#html-body
1124 Why is the Docutils XHTML served as "Content-type: text/html"?
1125 --------------------------------------------------------------
1129 Docutils' HTML output looks like XHTML and is advertised as such::
1131 <?xml version="1.0" encoding="utf-8" ?>
1132 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1133 "https://www.w3.org/TR/xht ml1/DTD/xhtml1-transitional.dtd">
1135 But this is followed by::
1137 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1139 Shouldn't this be "application/xhtml+xml" instead of "text/html"?
1141 Short answer: if we didn't serve XHTML as "text/html" (which is a
1142 perfectly valid thing to do), it couldn't be viewed in Internet
1145 Long answer: In a perfect web, the Docutils XHTML output would be 100%
1146 strict XHTML. But it's not a perfect web, and a major source of
1147 imperfection is Internet Explorer. When the "html4css1"
1148 writer was created, IE represented the overwhelming majority of web
1149 browsers "in the wild".
1150 The behaviour is kept for backwards compatibility while
1151 modern, semantic HTML output is available with the "html5" writer.
1153 (Thanks to Martin F. Krafft, Robert Kern, Michael Foord, and Alan
1157 Python Source Reader
1158 ====================
1160 Can I use Docutils for Python auto-documentation?
1161 -------------------------------------------------
1163 Yes, in conjunction with other projects.
1165 The Sphinx_ documentation generator includes an autodoc module.
1167 .. _Sphinx: http://www.sphinx-doc.org
1169 Version 2.0 of Ed Loper's `Epydoc <http://epydoc.sourceforge.net/>`_
1170 supports reStructuredText-format docstrings for HTML output. Docutils
1171 0.3 or newer is required.
1173 Development of a Docutils-specific auto-documentation tool is suspended.
1175 .. Epydoc works by importing
1176 Python modules to be documented, whereas the Docutils-specific tool,
1177 described above, will parse modules without importing them (as with
1178 `HappyDoc <http://happydoc.sourceforge.net/>`_, which doesn't support
1181 The advantages of parsing over importing are security and flexibility;
1182 the disadvantage is complexity/difficulty.
1184 * Security: untrusted code that shouldn't be executed can be parsed;
1185 importing a module executes its top-level code.
1186 * Flexibility: comments and unofficial docstrings (those not supported
1187 by Python syntax) can only be processed by parsing.
1188 * Complexity/difficulty: it's a lot harder to parse and analyze a
1189 module than it is to ``import`` and analyze one.
1191 For more details, please see "Docstring Extraction Rules"
1192 in :PEP:`258`, item 3 ("How").
1198 Is the Docutils document model based on any existing XML models?
1199 ----------------------------------------------------------------
1201 Not directly, no. It borrows bits from DocBook, HTML, and others. I
1202 (David Goodger) have designed several document models over the years,
1203 and have my own biases. The Docutils document model is designed for
1204 simplicity and extensibility, and has been influenced by the needs of
1205 the reStructuredText markup.
1210 How to make code contributions that are easily accepted
1211 -------------------------------------------------------
1213 * Follow the `Python coding conventions`_ and `documentation
1214 conventions`_ in the Docutils Policies.
1215 Ensure the addition works with all `supported Python versions`_.
1217 Look at the Docutils sources to see how similar features are
1218 implemented, learn to do it "the Docutils way".
1220 * Prepare tests_. Test cases are also examples and showcases for new
1223 * Include documentation.
1225 * For larger changes, consider creating a `feature branch`_ in a
1226 Docutils repository_ checkout. [#]_
1228 * Mail your patch to the Docutils-develop_ mailing list or attach it to the
1229 relevant ticket at Docutils' `bug tracker`_ or `feature request tracker`_.
1230 We accept patches created with diff, SVN, or Git.
1232 The developers will make sure that contributions fit nicely into Docutils.
1233 This might involve discussing (and compromising on) design and
1234 implementation details. It might also lead to the conclusion that the
1235 addition fits better in the `extensions and related projects`_.
1237 .. [#] Working with branches is much easier with Git_. You can get a Git
1238 clone of the repository from http://repo.or.cz/w/docutils.git or with
1241 .. _Python coding conventions: docs/dev/policies.html#python-coding-conventions
1242 .. _documentation conventions: docs/dev/policies.html#documentation-conventions
1243 .. _tests: docs/dev/testing.html
1244 .. _supported Python versions: README.html#requirements
1245 .. _feature branch: docs/dev/policies.html#feature-branch
1246 .. _Git: http://git-scm.com/
1247 .. _bug tracker: https://sourceforge.net/p/docutils/bugs/
1256 indent-tabs-mode: nil
1257 sentence-end-double-space: t
1261 .. Here's a code css to make a table colourful::
1266 background-color: #ede;
1269 /* alternating colors in table rows */
1270 table.docutils tr:nth-child(even) {
1271 background-color: #F3F3FF;
1273 table.docutils tr:nth-child(odd) {
1274 background-color: #FFFFEE;
1278 border-style: solid none solid none;
1279 border-width: 1px 0 1px 0;
1280 border-color: #AAAAAA;