Version: 0.18.1b
[docutils.git] / docutils / FAQ.txt
blob617ccbe534dcdeeb6a0e8168c86df6bfb1652201
1 .. -*- coding: utf-8 -*-
4 .. NOTE TO MAINTAINERS: Please add new questions to the end of their
5    sections, so section/question numbers remain stable.
8 ===========================================
9  Docutils FAQ (Frequently Asked Questions)
10 ===========================================
12 :Date: $Date$
13 :Revision: $Revision$
14 :Web site: https://docutils.sourceforge.io/
15 :Copyright: This document has been placed in the public domain.
17 .. contents::
18 .. sectnum::
21 This is a work in progress.  If you are reading a local copy, the
22 `master copy`_ might be newer.  This document uses are relative links;
23 if they don't work, please use the `master copy`_.
25 Please feel free to ask questions and/or provide answers; send email
26 to the `Docutils-users`_ mailing list.  Project members should feel
27 free to edit the source text file directly.
29 .. _master copy: https://docutils.sourceforge.io/FAQ.html
30 .. _let us know:
31 .. _Docutils-users: docs/user/mailing-lists.html#docutils-users
35 Docutils
36 ========
38 What is Docutils?
39 -----------------
41 Docutils_ is a system for processing plaintext documentation into
42 useful formats, such as HTML, XML, and LaTeX.  It supports multiple
43 types of input, such as standalone files, `PEPs (Python Enhancement
44 Proposals)`_, and string input. Client code may add other input types,
45 e.g. Sphinx_ comes with an extension to extract inline documentation
46 from Python modules and packages.
48 The Docutils distribution consists of:
50 * a library (the "docutils" package), which `can be used by client
51   code`_;
52 * several `front-end tools`_ (such as ``rst2html.py``, which converts
53   reStructuredText input into HTML output);
54 * a `test suite`_; and
55 * documentation_.
57 For an overview of the Docutils project implementation, see `PEP
58 258`_, "Docutils Design Specification".
60 Docutils is implemented in Python_.
62 .. _Docutils: https://docutils.sourceforge.io/
63 .. _PEPs (Python Enhancement Proposals):
64    http://www.python.org/peps/pep-0012.html
65 .. _can be used by client code: docs/api/publisher.html
66 .. _front-end tools: docs/user/tools.html
67 .. _test suite: docs/dev/testing.html
68 .. _documentation: docs/index.html
69 .. _PEP 258: http://www.python.org/peps/pep-0258.html
70 .. _Python: http://www.python.org/
73 Why is it called "Docutils"?
74 ----------------------------
76 Docutils is short for "Python Documentation Utilities".  The name
77 "Docutils" was inspired by "Distutils", the Python Distribution
78 Utilities architected by Greg Ward, a component of Python's standard
79 library.
81 The earliest known use of the term "docutils" in a Python context was
82 a `fleeting reference`__ in a message by Fred Drake on 1999-12-02 in
83 the Python Doc-SIG mailing list.  It was suggested `as a project
84 name`__ on 2000-11-27 on Doc-SIG, again by Fred Drake, in response to
85 a question from Tony "Tibs" Ibbs: "What do we want to *call* this
86 thing?".  This was shortly after David Goodger first `announced
87 reStructuredText`__ on Doc-SIG.
89 Tibs used the name "Docutils" for `his effort`__ "to document what the
90 Python docutils package should support, with a particular emphasis on
91 documentation strings".  Tibs joined the current project (and its
92 predecessors) and graciously donated the name.
94 For more history of reStructuredText and the Docutils project, see `An
95 Introduction to reStructuredText`_.
97 Please note that the name is "Docutils", not "DocUtils" or "Doc-Utils"
98 or any other variation.  It is pronounced as in "DOCumentation
99 UTILitieS", with emphasis on the first syllable.
101 .. _An Introduction to reStructuredText: docs/ref/rst/introduction.html
102 __ http://mail.python.org/pipermail/doc-sig/1999-December/000878.html
103 __ http://mail.python.org/pipermail/doc-sig/2000-November/001252.html
104 __ http://mail.python.org/pipermail/doc-sig/2000-November/001239.html
105 __ http://homepage.ntlworld.com/tibsnjoan/docutils/STpy.html
108 Is there a GUI authoring environment for Docutils?
109 --------------------------------------------------
111 See the links to editors_ supporting reStructuredText.
113 .. _editors: docs/user/links.html#editors
116 What is the status of the Docutils project?
117 -------------------------------------------
119 Docutils is mainly stable, with documented APIs and architecture
120 subject to change after announcement and a transition period.
122 We fix bugs as they are reported.  This means the code from the
123 repository_ (or the snapshots_) is the most stable as well as the most
124 featureful most of the time.
127 What is the Docutils project release policy?
128 --------------------------------------------
130 Besides the regular releases_, we provide automatically-generated
131 snapshots_ which always contain the latest code from the repository_.
132 As the project matures, we may formalize on a
133 stable/development-branch scheme, but we're not using anything like
134 that yet.
136 .. _releases: https://pypi.org/project/docutils/#history
137 .. _snapshots: https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/
138 .. _repository: docs/dev/repository.html
141 How can I get a new feature into Docutils?
142 ------------------------------------------
144 Present your idea at the docutils-develop_ mailing list
145 or file a ticket at Docutils' `feature request tracker`_.
147 See the `Docutils Policies`__ for a more detailed answer.
149 .. _docutils-develop: docs/user/mailing-lists.html#docutils-develop
150 .. _feature request tracker:
151     http://sourceforge.net/p/docutils/feature-requests/
152 __ docs/dev/policies.html#how-to-get-a-new-feature-into-docutils
154 reStructuredText
155 ================
157 What is reStructuredText?
158 -------------------------
160 reStructuredText_ is an easy-to-read, what-you-see-is-what-you-get
161 plaintext markup syntax and parser system.  The reStructuredText
162 parser is a component of Docutils_.  reStructuredText is a revision
163 and reinterpretation of the StructuredText_ and Setext_ lightweight
164 markup systems.
166 If you are reading this on the web, you can see for yourself.  `The
167 source for this FAQ <FAQ.txt>`_ is written in reStructuredText; open
168 it in another window and compare them side by side.
170 `A ReStructuredText Primer`_ and the `Quick reStructuredText`_ user
171 reference are a good place to start.  The `reStructuredText Markup
172 Specification`_ is a detailed technical specification.
174 .. _A ReStructuredText Primer: docs/user/rst/quickstart.html
175 .. _Quick reStructuredText: docs/user/rst/quickref.html
176 .. _reStructuredText Markup Specification:
177    docs/ref/rst/restructuredtext.html
178 .. _reStructuredText: https://docutils.sourceforge.io/rst.html
179 .. _StructuredText:
180    http://dev.zope.org/Members/jim/StructuredTextWiki/FrontPage/
181 .. _Setext: https://docutils.sourceforge.io/mirror/setext.html
184 Why is it called "reStructuredText"?
185 ------------------------------------
187 The name came from a combination of "StructuredText", one of
188 reStructuredText's predecessors, with "re": "revised", "reworked", and
189 "reinterpreted", and as in the ``re.py`` regular expression module.
190 For a detailed history of reStructuredText and the Docutils project,
191 see `An Introduction to reStructuredText`_.
193 "reStructuredText" is **ONE** word, *not two!*
196 What's the standard abbreviation for "reStructuredText"?
197 --------------------------------------------------------
199 "RST" and "ReST" (or "reST") are both acceptable.  Care should be
200 taken with capitalization, to avoid confusion with "REST__", an
201 acronym for "Representational State Transfer".
203 The abbreviations "reSTX" and "rSTX"/"rstx" should **not** be used;
204 they overemphasize reStructuredText's predecessor, Zope's
205 StructuredText.
207 __ http://en.wikipedia.org/wiki/Representational_State_Transfer
210 What's the standard filename extension for a reStructuredText file?
211 -------------------------------------------------------------------
213 It's ".txt".  Some people would like to use ".rest" or ".rst" or
214 ".restx", but why bother?  ReStructuredText source files are meant to
215 be readable as plaintext, and most operating systems already associate
216 ".txt" with text files.  Using a specialized filename extension would
217 require that users alter their OS settings, which is something that
218 many users will not be willing or able to do.
220 Also see `What's the official MIME type for reStructuredText data?`_
223 Are there any reStructuredText editor extensions?
224 -------------------------------------------------
226 See the list of editors_ supporting reStructuredText.
229 How can I indicate the document title?  Subtitle?
230 -------------------------------------------------
232 A uniquely-adorned section title at the beginning of a document is
233 treated specially, as the document title.  Similarly, a
234 uniquely-adorned section title immediately after the document title
235 becomes the document subtitle.  For example::
237     This is the Document Title
238     ==========================
240     This is the Document Subtitle
241     -----------------------------
243     Here's an ordinary paragraph.
245 Counterexample::
247     Here's an ordinary paragraph.
249     This is *not* a Document Title
250     ==============================
252     The "ordinary paragraph" above the section title
253     prevents it from becoming the document title.
255 Another counterexample::
257     This is not the Document Title,  because...
258     ===========================================
260     Here's an ordinary paragraph.
262     ... the title adornment is not unique
263     =====================================
265     Another ordinary paragraph.
268 How can I represent esoteric characters (e.g. character entities) in a document?
269 --------------------------------------------------------------------------------
271 For example, say you want an em-dash (XML character entity &mdash;,
272 Unicode character U+2014) in your document: use a real em-dash.
273 Insert concrete characters (e.g. type a *real* em-dash) into your
274 input file, using whatever encoding suits your application, and tell
275 Docutils the input encoding.  Docutils uses Unicode internally, so the
276 em-dash character is a real em-dash internally.
278 Emacs users should refer to the `Emacs Support for reStructuredText`__
279 document.  Tips for other editors are welcome.
281 __ tools/editors/emacs/README.html
283 ReStructuredText has no character entity subsystem; it doesn't know
284 anything about XML charents.  To Docutils, "&mdash;" in input text is
285 7 discrete characters; no interpretation happens.  When writing HTML,
286 the "&" is converted to "&amp;", so in the raw output you'd see
287 "&amp;mdash;".  There's no difference in interpretation for text
288 inside or outside inline literals or literal blocks -- there's no
289 character entity interpretation in either case.
291 If you can't use a Unicode-compatible encoding and must rely on 7-bit
292 ASCII, there is a workaround.  New in Docutils 0.3.10 is a set of
293 `Standard Substitution Definition Sets`_, which provide equivalents of
294 XML & HTML character entity sets as substitution definitions.  For
295 example, the Japanese yen currency symbol can be used as follows::
297     .. include:: <xhtml1-lat1.txt>
299     |yen| 600 for a complete meal?  That's cheap!
301 Thanks to David Priest for the original idea.
303 If you insist on using XML-style charents, you'll have to implement a
304 pre-processing system to convert to UTF-8 or something.  That
305 introduces complications though; you can no longer *write* about
306 charents naturally; instead of writing "&mdash;" you'd have to write
307 "&amp;mdash;".
309 For the common case of long dashes, you might also want to insert the
310 following substitution definitions into your document (both of them are
311 using the "unicode_" directive)::
313     .. |--| unicode:: U+2013   .. en dash
314     .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
315        :trim:
317 .. |--| unicode:: U+2013   .. en dash
318 .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
319    :trim:
321 Now you can write dashes using pure ASCII: "``foo |--| bar; foo |---|
322 bar``", rendered as "foo |--| bar; foo |---| bar".
323 The ``:trim:`` option for
324 the em dash is necessary because you cannot write "``foo|---|bar``";
325 thus you need to add spaces ("``foo |---| bar``") and advise the
326 reStructuredText parser to trim the spaces.
328 .. _Standard Substitution Definition Sets: docs/ref/rst/definitions.html
329 .. _unicode: docs/ref/rst/directives.html#unicode-character-codes
330 .. _are available: https://docutils.sourceforge.io/tmp/charents/
331 .. _tarball: https://docutils.sourceforge.io/tmp/charents.tgz
332 .. _description and instructions:
333    https://docutils.sourceforge.io/tmp/charents/README.html
334 .. _to-do list: docs/dev/todo.html
337 How can I generate backticks using a Scandinavian keyboard?
338 -----------------------------------------------------------
340 The use of backticks in reStructuredText is a bit awkward with
341 Scandinavian keyboards, where the backtick is a "dead" key.  To get
342 one ` character one must press SHIFT-` + SPACE.
344 Unfortunately, with all the variations out there, there's no way to
345 please everyone.  For Scandinavian programmers and technical writers,
346 this is not limited to reStructuredText but affects many languages and
347 environments.
349 Possible solutions include
351 * If you have to input a lot of backticks, simply type one in the
352   normal/awkward way, select it, copy and then paste the rest (CTRL-V
353   is a lot faster than SHIFT-` + SPACE).
355 * Use keyboard macros.
357 * Remap the keyboard.  The Scandinavian keyboard layout is awkward for
358   other programming/technical characters too; for example, []{}
359   etc. are a bit awkward compared to US keyboards.
361   According to Axel Kollmorgen,
363       Under Windows, you can use the `Microsoft Keyboard Layout Creator
364       <http://www.microsoft.com/globaldev/tools/msklc.mspx>`__ to easily
365       map the backtick key to a real backtick (no dead key). took me
366       five minutes to load my default (german) keyboard layout, untick
367       "Dead Key?" from the backtick key properties ("in all shift
368       states"), "build dll and setup package", install the generated
369       .msi, and add my custom keyboard layout via Control Panel >
370       Regional and Language Options > Languages > Details > Add
371       Keyboard layout (and setting it as default "when you start your
372       computer").
374 * Use a virtual/screen keyboard or character palette, such as:
376   - `Web-based keyboards <http://keyboard.lab.co.il/>`__ (IE only
377     unfortunately).
378   - Windows: `Click-N-Type <http://www.lakefolks.org/cnt/>`__.
379   - Mac OS X: the Character Palette can store a set of favorite
380     characters for easy input.  Open System Preferences,
381     International, Input Menu tab, enable "Show input menu in menu
382     bar", and be sure that Character Palette is enabled in the list.
384 If anyone knows of other/better solutions, please `let us know`_.
387 Are there any tools for HTML/XML-to-reStructuredText?  (Round-tripping)
388 -----------------------------------------------------------------------
390 People have tossed the idea around, and some implementations of
391 reStructuredText-generating tools can be found in the `Docutils Link
392 List`_.
394 There's no reason why reStructuredText should not be round-trippable
395 to/from XML; any technicalities which prevent round-tripping would be
396 considered bugs.  Whitespace would not be identical, but paragraphs
397 shouldn't suffer.  The tricky parts would be the smaller details, like
398 links and IDs and other bookkeeping.
400 For HTML, true round-tripping may not be possible.  Even adding lots
401 of extra "class" attributes may not be enough.  A "simple HTML" to RST
402 filter is possible -- for some definition of "simple HTML" -- but HTML
403 is used as dumb formatting so much that such a filter may not be
404 particularly useful.  An 80/20 approach should work though: build a
405 tool that does 80% of the work automatically, leaving the other 20%
406 for manual tweaks.
408 .. _Docutils Link List: docs/user/links.html
411 Are there any Wikis that use reStructuredText syntax?
412 -----------------------------------------------------
414 There are several, with various degrees of completeness.  With no
415 implied endorsement or recommendation, and in no particular order:
417 * `Ian Bicking's experimental code
418   <http://docutils.sf.net/sandbox/ianb/wiki/Wiki.py>`__
420 * `MoinMoin <http://moinmoin.wikiwikiweb.de/>`__ has some support;
421   `here's a sample <http://moinmoin.wikiwikiweb.de/RestSample>`__
423 * Zope-based `Zwiki <http://zwiki.org/>`__
425 * Zope3-based Zwiki (in the Zope 3 source tree as
426   ``zope.products.zwiki``)
428 * `StikiWiki <http://mithrandr.moria.org/code/stikiwiki/>`__
430 * `Trac <http://trac.edgewall.com//>`__ `supports using
431   reStructuredText
432   <http://trac.edgewall.com//wiki/WikiRestructuredText>`__ as
433   an alternative to wiki markup. This includes support for `TracLinks
434   <http://trac.edgewall.com//wiki/TracLinks>`__ from within
435   RST text via a custom RST reference-directive or, even easier, an
436   interpreted text role 'trac'
438 Please `let us know`_ of any other reStructuredText Wikis.
440 .. dead link
441 .. The example application for the `Web Framework Shootout
442 .. <http://colorstudy.com/docs/shootout.html>`__ article is a Wiki using
443 .. reStructuredText.
446 Are there any Weblog (Blog) projects that use reStructuredText syntax?
447 ----------------------------------------------------------------------
449 With no implied endorsement or recommendation, and in no particular
450 order:
452 * `Firedrop <http://www.voidspace.org.uk/python/firedrop2/>`__
453 * `PyBloxsom <http://pyblosxom.sourceforge.net/>`__
454 * `Lino WebMan <http://lino.sourceforge.net/webman.html>`__
455 * `Pelican <http://blog.getpelican.com/>`__
456   (also  listed `on PyPi <http://pypi.python.org/pypi/pelican>`__)
458 Please `let us know`_ of any other reStructuredText Blogs.
461 .. _Can lists be indented without generating block quotes?:
463 How should I mark up lists?
464 ---------------------------
466 Bullet_ & enumerated_ list markup is very intuitive but there are 2
467 points that must be noted:
469 .. _bullet: docs/ref/rst/restructuredtext.html#bullet-lists
470 .. _enumerated: docs/ref/rst/restructuredtext.html#enumerated-lists
472 1. Lists should **not** be indented.  This is correct::
474        paragraph
476        * list item 1
478          * nested item 1.1
479          * nested item 1.2
481        * list item 2
483    while this is probably incorrect::
485        paragraph
487          * list item 1
489              * nested item 1.1
490              * nested item 1.2
492          * list item 2
494    The extra indentation (of the list containing items 1.1 and 1.2) is
495    recognized as a block quote.  This is usually not what you mean and
496    it causes the list in the output to be indented too much.
498 2. There **must** be blank lines around list items, except between
499    items of the same level, where blank lines are optional.  The
500    example above shows this.
502 Note that formatting of the *output* is independent of the input, and
503 is decided by the writer and the stylesheet.  For instance, lists
504 *are* indented in HTML output by default.  See `How are lists
505 formatted in HTML?`_ for details.
508 Could lists be indented without generating block quotes?
509 --------------------------------------------------------
511 Some people like to write lists with indentation but don't intend a
512 blockquote context.  There has been a lot of discussion about allowing
513 this in reStructuredText, but there are some issues that would need to
514 be resolved before it could be implemented.  There is a summary of the
515 issues and pointers to the discussions in `the to-do list`__.
517 __ docs/dev/todo.html#indented-lists
520 Could the requirement for blank lines around lists be relaxed?
521 --------------------------------------------------------------
523 Short answer: no.
525 In reStructuredText, it would be impossible to unambiguously mark up
526 and parse lists without blank lines before and after.  Deeply nested
527 lists may look ugly with so many blank lines, but it's a price we pay
528 for unambiguous markup.  Some other plaintext markup systems do not
529 require blank lines in nested lists, but they have to compromise
530 somehow, either accepting ambiguity or requiring extra complexity.
531 For example, `Epytext <http://epydoc.sf.net/epytext.html#list>`__ does
532 not require blank lines around lists, but it does require that lists
533 be indented and that ambiguous cases be escaped.
536 How can I include mathematical equations in documents?
537 ------------------------------------------------------
539 Use the `math directive`_ and `math role`_, available since Docutils 0.8.
541 .. _math directive: docs/ref/rst/directives.html#math
542 .. _math role: docs/ref/rst/roles.html#math
545 Is nested inline markup possible?
546 ---------------------------------
548 Not currently, no.  It's on the `to-do list`__ (`details here`__), and
549 hopefully will be part of the reStructuredText parser soon.  At that
550 time, markup like this will become possible::
552     Here is some *emphasized text containing a `hyperlink`_ and
553     ``inline literals``*.
555 __ docs/dev/todo.html#nested-inline-markup
556 __ docs/dev/rst/alternatives.html#nested-inline-markup
558 There are workarounds, but they are either convoluted or ugly or both.
559 They are not recommended.
561 * Inline markup can be combined with hyperlinks using `substitution
562   definitions`__ and references__ with the `"replace" directive`__.
563   For example::
565       Here is an |emphasized hyperlink|_.
567       .. |emphasized hyperlink| replace:: *emphasized hyperlink*
568       .. _emphasized hyperlink: http://example.org
570   It is not possible for just a portion of the replacement text to be
571   a hyperlink; it's the entire replacement text or nothing.
573   __ docs/ref/rst/restructuredtext.html#substitution-definitions
574   __ docs/ref/rst/restructuredtext.html#substitution-references
575   __ docs/ref/rst/directives.html#replace
577 * The `"raw" directive`__ can be used to insert raw HTML into HTML
578   output::
580       Here is some |stuff|.
582       .. |stuff| raw:: html
584          <em>emphasized text containing a
585          <a href="http://example.org">hyperlink</a> and
586          <tt>inline literals</tt></em>
588   Raw LaTeX is supported for LaTeX output, etc.
590   __ docs/ref/rst/directives.html#raw
593 How to indicate a line break or a significant newline?
594 ------------------------------------------------------
596 `Line blocks`__ are designed for address blocks, verse, and other
597 cases where line breaks are significant and must be preserved.  Unlike
598 literal blocks, the typeface is not changed, and inline markup is
599 recognized.  For example::
601     | A one, two, a one two three four
602     |
603     | Half a bee, philosophically,
604     |     must, *ipso facto*, half not be.
605     | But half the bee has got to be,
606     |     *vis a vis* its entity.  D'you see?
607     |
608     | But can a bee be said to be
609     |     or not to be an entire bee,
610     |         when half the bee is not a bee,
611     |             due to some ancient injury?
612     |
613     | Singing...
615 __ docs/ref/rst/restructuredtext.html#line-blocks
617 Here's a workaround for manually inserting explicit line breaks in
618 HTML output::
620     .. |br| raw:: html
622        <br />
624     I want to break this line here: |br| this is after the break.
626     If the extra whitespace bothers you, |br|\ backslash-escape it.
629 A URL containing asterisks doesn't work.  What to do?
630 -----------------------------------------------------
632 Asterisks are valid URL characters (see :RFC:`2396`), sometimes used
633 in URLs.  For example::
635     http://cvs.example.org/viewcvs.py/*checkout*/module/file
637 Unfortunately, the parser thinks the asterisks are indicating
638 emphasis.  The slashes serve as delineating punctuation, allowing the
639 asterisks to be recognized as markup.  The example above is separated
640 by the parser into a truncated URL, an emphasized word, and some
641 regular text::
643     http://cvs.example.org/viewcvs.py/
644     *checkout*
645     /module/file
647 To turn off markup recognition, use a backslash to escape at least the
648 first asterisk, like this::
650     http://cvs.example.org/viewcvs.py/\*checkout*/module/file
652 Escaping the second asterisk doesn't hurt, but it isn't necessary.
655 How can I make a literal block with *some* formatting?
656 ------------------------------------------------------
658 Use the `parsed-literal`_ directive.
660 .. _parsed-literal: docs/ref/rst/directives.html#parsed-literal
662 Scenario: a document contains some source code, which calls for a
663 literal block to preserve linebreaks and whitespace.  But part of the
664 source code should be formatted, for example as emphasis or as a
665 hyperlink.  This calls for a *parsed* literal block::
667     .. parsed-literal::
669        print "Hello world!"  # *tricky* code [1]_
671 The emphasis (``*tricky*``) and footnote reference (``[1]_``) will be
672 parsed.
675 Can reStructuredText be used for web or generic templating?
676 -----------------------------------------------------------
678 Docutils and reStructuredText can be used with or as a component of a
679 templating system, but they do not themselves include templating
680 functionality.  Templating should simply be left to dedicated
681 templating systems.  Users can choose a templating system to apply to
682 their reStructuredText documents as best serves their interests.
684 There are many good templating systems for Python (ht2html_, YAPTU_,
685 Quixote_'s PTL, Cheetah_, etc.; see this non-exhaustive list of `some
686 other templating systems`_), and many more for other languages, each
687 with different approaches.  We invite you to try several and find one
688 you like.  If you adapt it to use Docutils/reStructuredText, please
689 consider contributing the code to Docutils or `let us know`_ and we'll
690 keep a list here.
692 One reST-specific web templating system is `rest2web
693 <http://www.voidspace.org.uk/python/rest2web>`_, a tool for
694 automatically building websites, or parts of websites.
696 .. _ht2html: http://ht2html.sourceforge.net/
697 .. _YAPTU:
698    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305
699 .. _Quixote: http://www.mems-exchange.org/software/quixote/
700 .. _Cheetah: http://www.cheetahtemplate.org/
701 .. _some other templating systems:
702    http://webware.sourceforge.net/Papers/Templates/
705 How can I mark up a FAQ or other list of questions & answers?
706 -------------------------------------------------------------
708 There is no specific syntax for FAQs and Q&A lists.  Here are two
709 options:
711 1. For a FAQ (Frequently Asked Questions, usually with answers), a
712    convenient way to mark up the questions is as section titles, with
713    the answer(s) as section content.  This document is marked up in
714    this way.
716    The advantages of using section titles for questions are: sections
717    can be numbered automatically, and a table of contents can be
718    generated automatically.  One limitation of this format is that
719    questions must fit on one line (section titles may not wrap, in the
720    source text).  For very long questions, the title may be a summary
721    of the question, with the full question in the section body.
723 2. Field lists work well as Q&A lists::
725        :Q: What kind of questions can we
726            put here?
728        :A: Any kind we like!
730    In order to separate questions, lists can be used:
732        1. :Q: What kind of question can we
733               put here?
734           :A: Any kind we like!
736        2. :Q: How many answers can a question have?
737           :A: It can have one,
738           :A: or more.
739           :A3: Answers can be numbered like this.
740           :A: 1. Or like this.
741               2. We're flexible!
743    If you don't want to number or otherwise mark questions, you can
744    use an empty comment between individual field lists to separate
745    them::
747        :Q: First question?
748        :A: Answer.
750        ..
752        :Q: Second question?
753        :A: Answer.
756 .. _bidi:
758 Can I produce documents in right-to-left languages?
759 ---------------------------------------------------
761 Languages written from right to left, such as Arabic and Hebrew, must
762 be reordered according to the `Unicode Bidi Algorithm`_.  This
763 requires support from the editor and special markup in the output
764 format.
766 The source format of reStructuredText is relatively bidi-friendly:
767 most constructs are denoted by punctuation without intrusion of
768 English and when you must write in English, it's usually on a separate
769 line.  So any editor that auto-detects direction per-line (like gedit
770 or geresh_) will suffice.
772 Moreover, it's possible to translate_ all reStructuredText keywords.
773 Docutils 0.17 includes translations for Arab, Hebrew, and
774 Persian/Farsi.  This should allow reasonable use of editors limited to
775 a single base direction for the whole document (like Notepad, Vim and
776 text boxes in Firefox).
778 .. _Unicode Bidi Algorithm: http://www.unicode.org/reports/tr9/
779 .. _geresh: http://www.typo.co.il/~mooffie/geresh/
780 .. _translate: docs/howto/i18n.html
782 The second problem is bidi markup of the output.  There is an almost
783 transparent implicit solution for HTML:
785 * Grab http://cben-hacks.sourceforge.net/bidi/hibidi.py and
786   http://cben-hacks.sourceforge.net/bidi/rst2html_hibidi.py.
787   Put them both in the same directory and make them executable.
789 * Use ``rst2html_hibidi.py`` instead of ``rst2html.py``.
791 * It infers dir attributes in the HTML from the text.  It does it
792   hierachically, giving much better results than usual.  You can still
793   use LRM/RLM and LRE/RLE/PDF control codes to help it.
795   * If you want the gory details: See the full theory_, and note the
796     incomplete practice_ (this is still a partial implementation - but
797     sufficient for most needs).
799     .. _theory: http://cben-hacks.sf.net/bidi/hibidi.html
800     .. _practice: http://cben-hacks.sf.net/bidi/hibidi.html#practice
802 There is also an explicit way to set directions through CSS and
803 classes in the HTML:
805 * Copy ``default.css`` to a new file and add relevant parts of the
806   following::
808       /* Use these two if the main document direction is RTL */
809       body { direction: rtl; }
810       div.sidebar { float: left !important; }
812       /* The next 3 rules are very useful in documents containing pieces
813       of code in english */
814       /* Use this if you all your literal blocks (::) are LTR */
815       pre {direction: ltr; unicode-bidi: embed; }
816       /* Use this if you all your inline literals (``) are LTR */
817       tt {direction: ltr; unicode-bidi: embed; }
818       /* Use this if you all your interpreted text (`) is LTR */
819       cite {direction: ltr; unicode-bidi: embed; }
821       /* Allow manual direction override by class directive and roles */
822       .rtl { direction: rtl; }
823       .ltr { direction: ltr; }
825 * Select this new stylesheet with ``--stylesheet=<file>`` or the
826   stylesheet_ setting.
828 * Now if you need to override the direction of some element (from a
829   paragraph to a whole section), write::
831       .. class:: rtl
833   or::
835       .. class:: ltr
837   before it (see the class_ directive for details).
839 * To change the direction of some inline text fragment, you can use
840   RLE/LRE/PDF control characters, or write ``:rtl:`RTL text``` /
841   ``:ltr:`RTL text```.  To use the latter syntax, you must write this
842   once at the beginning of your document::
844       .. role:: ltr
845       .. role:: rtl
847 .. _stylesheet: docs/user/config.html#stylesheet
848 .. _class: docs/ref/rst/directives.txt#class
850 LaTeX is quite hard to implement (it doesn't support the bidi
851 algorithm, so all direction changes - even numbers in RTL text - must
852 be explicitly marked).  Other formats are more-or-less easy.
854 If you have any questions/problems/bugs related to bidi with docutils,
855 ask `Beni Cherniavsky`__ directly or the `Docutils-users`_ mailing
856 list.
858 __ mailto:cben@users.sf.net
861 What's the official MIME type for reStructuredText data?
862 --------------------------------------------------------
864 While there is no registered MIME type for reStructuredText, the
865 "official unofficial" standard MIME type is "text/x-rst". [#]_  This was
866 invented for the build system for PEPs (Python Enhancement Proposals),
867 and it's used by the python.org web site build system.
869 Also see `What's the standard filename extension for a
870 reStructuredText file?`_
872 .. [#] The "x-" prefix means it's an unregistered MIME type.
875 HTML Writer
876 ===========
878 What is the status of the HTML Writer?
879 --------------------------------------
881 The default HTML Writer module, ``docutils/writers/html4css1.py``, is
882 a proof-of-concept reference implementation.  While it is a complete
883 implementation, some aspects of the HTML it produces may be outdated or
884 incompatible with older browsers or specialized applications (such as
885 web templating).
887 For the full selection see `Docutils HTML writers`_
889 .. _Docutils HTML writers: docs/user/html.html
891 What browsers are supported?
892 ----------------------------
894 No specific browser is targeted; all modern graphical browsers should
895 work.  Some older browsers, text-only browsers, and browsers without
896 full CSS support are known to produce inferior results.  Firefox,
897 Safari, Opera, Chrome, Edge, and MS Internet Explorer (version 5.0 and up)
898 are known to give good results.  Reports of experiences with other
899 browsers are welcome.
902 Unexpected results from tools/rst2html.py: H1, H1 instead of H1, H2.  Why?
903 --------------------------------------------------------------------------
905 Here's the question in full:
907     I have this text::
909         Heading 1
910         =========
912         All my life, I wanted to be H1.
914         Heading 1.1
915         -----------
917         But along came H1, and so shouldn't I be H2?
918         No!  I'm H1!
920         Heading 1.1.1
921         *************
923         Yeah, imagine me, I'm stuck at H3!  No?!?
925     When I run it through tools/rst2html.py, I get unexpected results
926     (below).  I was expecting H1, H2, then H3; instead, I get H1, H1,
927     H2::
929         ...
930         <html lang="en">
931         <head>
932         ...
933         <title>Heading 1</title>
934         </head>
935         <body>
936         <div class="document" id="heading-1">
937         <h1 class="title">Heading 1</h1>                <-- first H1
938         <p>All my life, I wanted to be H1.</p>
939         <div class="section" id="heading-1-1">
940         <h1><a name="heading-1-1">Heading 1.1</a></h1>        <-- H1
941         <p>But along came H1, and so now I must be H2.</p>
942         <div class="section" id="heading-1-1-1">
943         <h2><a name="heading-1-1-1">Heading 1.1.1</a></h2>
944         <p>Yeah, imagine me, I'm stuck at H3!</p>
945         ...
947     What gives?
949 Check the "class" attribute on the H1 tags, and you will see a
950 difference.  The first H1 is actually ``<h1 class="title">``; this is
951 the document title, and the default stylesheet renders it centered.
952 There can also be an ``<h2 class="subtitle">`` for the document
953 subtitle.
955 If there's only one highest-level section title at the beginning of a
956 document, it is treated specially, as the document title.  (Similarly, a
957 lone second-highest-level section title may become the document
958 subtitle.)  See `How can I indicate the document title?  Subtitle?`_ for
959 details.  Rather than use a plain H1 for the document title, we use ``<h1
960 class="title">`` so that we can use H1 again within the document.  Why
961 do we do this?  HTML only has H1-H6, so by making H1 do double duty, we
962 effectively reserve these tags to provide 6 levels of heading beyond the
963 single document title.
965 With "html4css1", HTML is being used for dumb formatting for nothing
966 but final display. A stylesheet *is required*, and one is provided;
967 see `Docutils HTML writers`_.  Of course, you're
968 welcome to roll your own.  The default stylesheet provides rules to
969 format ``<h1 class="title">`` and ``<h2 class="subtitle">``
970 differently from ordinary ``<h1>`` and ``<h2>``::
972     h1.title {
973       text-align: center }
975     h2.subtitle {
976       text-align: center }
978 If you don't want the top section heading to be interpreted as a
979 title at all, disable the `doctitle_xform`_ setting
980 (``--no-doc-title`` option).  This will interpret your document
981 differently from the standard settings, which might not be a good
982 idea.  If you don't like the reuse of the H1 in the HTML output, you
983 can tweak the `initial_header_level`_ setting
984 (``--initial-header-level`` option) -- but unless you match its value
985 to your specific document, you might end up with bad HTML (e.g. H3
986 without H2).
988 .. _doctitle_xform: docs/user/config.html#doctitle-xform
989 .. _initial_header_level: docs/user/config.html#initial-header-level
991 (Thanks to Mark McEahern for the question and much of the answer.)
993 .. note:: For the html5 writer, `initial_header_level`_ defaults to
994    ``2`` because this is what the `HTML5 standard`__ expects as
995    start value for headings nested in <section> elements.
997    .. Sectioning content elements are always considered subsections of
998       their nearest ancestor *sectioning root* [#]_ or their nearest
999       ancestor element of *sectioning content*  [#]_, whichever is nearest,
1000       [...]
1002       .. [#] <blockquote>, <body>, <details>, <dialog>, <fieldset>,
1003              <figure>, <td>
1004       .. [#] <article>, <aside>, <nav>, <section>
1006       I.e., a top-level <section> is a subsection of <body>.
1008    __ https://www.w3.org/TR/html53/sections.html#headings-and-sections
1012 How are lists formatted in HTML?
1013 --------------------------------
1015 If list formatting looks strange, first check that you understand
1016 `list markup`__.
1018 __ `How should I mark up lists?`_
1020 * By default, HTML browsers indent lists relative to their context.
1021   This follows a long tradition in browsers (but isn't so established
1022   in print).  If you don't like it, you should change the stylesheet.
1024   This is different from how lists look in reStructuredText source.
1025   Extra indentation in the source indicates a blockquote, resulting in
1026   too much indentation in the browser.
1028 * A list item can contain multiple paragraphs etc.  In complex cases
1029   list items are separated by vertical space.  By default this spacing
1030   is omitted in "simple" lists.  A list is simple if every item
1031   contains a simple paragraph and/or a "simple" nested list.  For
1032   example:
1034       * text
1036         * simple
1038           * simple
1039           * simple
1041         * simple
1043         text after a nested list
1045       * multiple
1047         paragraphs
1049   In this example the nested lists are simple (and should appear
1050   compacted) but the outer list is not.
1052   If you want all lists to have equal spacing, disable the
1053   `compact_lists`_ setting (``--no-compact-lists`` option).  The
1054   precise spacing can be controlled in the stylesheet.
1056   Note again that this is not exactly WYSIWYG: it partially resembles
1057   the rules about blank lines being optional between list items in
1058   reStructuredText -- but adding/removing optional blank lines does
1059   not affect spacing in the output!  It's a feature, not a bug: you
1060   write it as you like but the output is styled consistently.
1062   .. _compact_lists: docs/user/config.html#compact-lists
1065 Why do enumerated lists only use numbers (no letters or roman numerals)?
1066 ------------------------------------------------------------------------
1068 The rendering of enumerators (the numbers or letters acting as list
1069 markers) is completely governed by the stylesheet, so either the
1070 browser can't find the stylesheet (try enabling the
1071 `embed_stylesheet`_ setting [``--embed-stylesheet`` option]), or the
1072 browser can't understand it (try a not too old Firefox, Chrome, Opera,
1073 Safari, Edge, or even MSIE).
1075 .. _embed_stylesheet: docs/user/config.html#embed-stylesheet
1078 There appear to be garbage characters in the HTML.  What's up?
1079 --------------------------------------------------------------
1081 What you're seeing is most probably not garbage, but the result of a
1082 mismatch between the actual encoding of the HTML output and the
1083 encoding your browser is expecting.  Your browser is misinterpreting
1084 the HTML data, which is encoded text.  A discussion of text encodings
1085 is beyond the scope of this FAQ; see one or more of these documents
1086 for more info:
1088 * `UTF-8 and Unicode FAQ for Unix/Linux
1089   <http://www.cl.cam.ac.uk/~mgk25/unicode.html>`_
1091 * Chapters 3 and 4 of `Introduction to i18n [Internationalization]
1092   <http://www.debian.org/doc/manuals/intro-i18n/>`_
1094 * `Python Unicode Tutorial
1095   <http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
1097 * `Python Unicode Objects: Some Observations on Working With Non-ASCII
1098   Character Sets <http://effbot.org/zone/unicode-objects.htm>`_
1100 The common case is with the default output encoding (UTF-8), when
1101 either numbered sections are used (via the "sectnum_" directive) or
1102 symbol-footnotes.  3 non-breaking spaces are inserted in each numbered
1103 section title, between the generated number and the title text.  Most
1104 footnote symbols are not available in ASCII, nor are non-breaking
1105 spaces.  When encoded with UTF-8 and viewed with ordinary ASCII tools,
1106 these characters will appear to be multi-character garbage.
1108 You may have an decoding problem in your browser (or editor, etc.).
1109 The encoding of the output is set to "utf-8", but your browser isn't
1110 recognizing that.  You can either try to fix your browser (enable
1111 "UTF-8 character set", sometimes called "Unicode"), or choose a
1112 different encoding for the HTML output.  You can also try
1113 ``--output-encoding=ascii:xmlcharrefreplace`` for HTML or XML, but not
1114 applicable to non-XMLish outputs (if using runtime
1115 settings/configuration files, use ``output_encoding=ascii`` and
1116 ``output_encoding_error_handler=xmlcharrefreplace``).
1118 If you're generating document fragments, the "Content-Type" metadata
1119 (between the HTML ``<head>`` and ``</head>`` tags) must agree with the
1120 encoding of the rest of the document.  For UTF-8, it should be::
1122     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1124 Also, Docutils normally generates an XML declaration as the first line
1125 of the output.  It must also match the document encoding.  For UTF-8::
1127     <?xml version="1.0" encoding="utf-8" ?>
1129 .. _sectnum: docs/ref/rst/directives.html#sectnum
1132 How can I retrieve the body of the HTML document?
1133 -------------------------------------------------
1135 (This is usually needed when using Docutils in conjunction with a
1136 templating system.)
1138 You can use the `docutils.core.publish_parts()`_ function, which
1139 returns a dictionary containing an 'html_body_' entry.
1141 .. _docutils.core.publish_parts(): docs/api/publisher.html#publish-parts
1142 .. _html_body: docs/api/publisher.html#html-body
1145 Why is the Docutils XHTML served as "Content-type: text/html"?
1146 --------------------------------------------------------------
1148 Full question:
1150     Docutils' HTML output looks like XHTML and is advertised as such::
1152       <?xml version="1.0" encoding="utf-8" ?>
1153       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1154        "http://www.w3.org/TR/xht ml1/DTD/xhtml1-transitional.dtd">
1156     But this is followed by::
1158       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1160     Shouldn't this be "application/xhtml+xml" instead of "text/html"?
1162 Short answer: if we didn't serve XHTML as "text/html" (which is a
1163 perfectly valid thing to do), it couldn't be viewed in Internet
1164 Explorer.
1166 Long answer: In a perfect web, the Docutils XHTML output would be 100%
1167 strict XHTML.  But it's not a perfect web, and a major source of
1168 imperfection is Internet Explorer.  When the "html4css1"
1169 writer was created, IE represented the overwhelming majority of web
1170 browsers "in the wild".
1171 The behaviour is kept for backwards compatibility while
1172 modern, semantic HTML output is available with the "html5" writer.
1174 (Thanks to Martin F. Krafft, Robert Kern, Michael Foord, and Alan
1175 G. Isaac.)
1178 Python Source Reader
1179 ====================
1181 Can I use Docutils for Python auto-documentation?
1182 -------------------------------------------------
1184 Yes, in conjunction with other projects.
1186 The Sphinx_ documentation generator includes an autodoc module.
1188 .. _Sphinx: http://sphinx.pocoo.org/index.html
1190 Version 2.0 of Ed Loper's `Epydoc <http://epydoc.sourceforge.net/>`_
1191 supports reStructuredText-format docstrings for HTML output.  Docutils
1192 0.3 or newer is required.  Development of a Docutils-specific
1193 auto-documentation tool will continue.  Epydoc works by importing
1194 Python modules to be documented, whereas the Docutils-specific tool,
1195 described above, will parse modules without importing them (as with
1196 `HappyDoc <http://happydoc.sourceforge.net/>`_, which doesn't support
1197 reStructuredText).
1199 The advantages of parsing over importing are security and flexibility;
1200 the disadvantage is complexity/difficulty.
1202 * Security: untrusted code that shouldn't be executed can be parsed;
1203   importing a module executes its top-level code.
1204 * Flexibility: comments and unofficial docstrings (those not supported
1205   by Python syntax) can only be processed by parsing.
1206 * Complexity/difficulty: it's a lot harder to parse and analyze a
1207   module than it is to ``import`` and analyze one.
1209 For more details, please see "Docstring Extraction Rules" in `PEP
1210 258`_, item 3 ("How").
1213 Miscellaneous
1214 =============
1216 Is the Docutils document model based on any existing XML models?
1217 ----------------------------------------------------------------
1219 Not directly, no.  It borrows bits from DocBook, HTML, and others.  I
1220 (David Goodger) have designed several document models over the years,
1221 and have my own biases.  The Docutils document model is designed for
1222 simplicity and extensibility, and has been influenced by the needs of
1223 the reStructuredText markup.
1227    Local Variables:
1228    mode: indented-text
1229    indent-tabs-mode: nil
1230    sentence-end-double-space: t
1231    fill-column: 70
1232    End:
1234 .. Here's a code css to make a table colourful::
1236    /* Table: */
1238    th {
1239        background-color: #ede;
1240    }
1242    /* alternating colors in table rows */
1243    table.docutils tr:nth-child(even) {
1244        background-color: #F3F3FF;
1245    }
1246    table.docutils tr:nth-child(odd) {
1247        background-color: #FFFFEE;
1248    }
1250    table.docutils tr {
1251        border-style: solid none solid none;
1252        border-width: 1px 0 1px 0;
1253        border-color: #AAAAAA;
1254    }