Minor fix to underlining function,
[docutils.git] / FAQ.txt
blob43ca284a416c82d611f907a32fb2a463da641e16
1 ===========================================
2  Docutils FAQ (Frequently Asked Questions)
3 ===========================================
5 :Date: $Date$
6 :Web site: http://docutils.sourceforge.net/
7 :Copyright: This document has been placed in the public domain.
9 .. Please note that until there's a Q&A-specific construct available,
10    this FAQ will use section titles for questions.  Therefore
11    questions must fit on one line.  The title may be a summary of the
12    question, with the full question in the section body.
15 .. contents::
16 .. sectnum::
19 This is a work in progress.  Please feel free to ask questions and/or
20 provide answers; `send email`__ to the `Docutils-Users mailing list`__
21 [1]_.  Project members should feel free to edit the source text file
22 directly.
24 .. [1] Due to overwhelming amounts of spam, the
25    docutils-users@lists.sourceforge.net mailing list has been set up
26    for subscriber posting only.  Non-subscribers who post to
27    docutils-users will receive a message with "Subject: Your message
28    to Docutils-users awaits moderator approval".  Legitimate messages
29    are accepted and posted as soon as possible (a list administrator
30    must verify the message manually).  If you'd like to subscribe to
31    docutils-users, please visit
32    <http://lists.sourceforge.net/lists/listinfo/docutils-users>.
34 .. _let us know:
35 __ mailto:docutils-users@lists.sourceforge.net
36 __ http://lists.sourceforge.net/lists/listinfo/docutils-users
39 Docutils
40 ========
42 What is Docutils?
43 -----------------
45 Docutils_ is a system for processing plaintext documentation into
46 useful formats, such as HTML, XML, and LaTeX.  It supports multiple
47 types of input, such as standalone files (implemented), inline
48 documentation from Python modules and packages (under development),
49 `PEPs (Python Enhancement Proposals)`_ (implemented), and others as
50 discovered.
52 For an overview of the Docutils project implementation, see `PEP
53 258`_, "Docutils Design Specification".
55 Docutils is implemented in Python_.
57 .. _Docutils: http://docutils.sourceforge.net/
58 .. _PEPs (Python Enhancement Proposals):
59    http://www.python.org/peps/pep-0012.html
60 .. _PEP 258: http://www.python.org/peps/pep-0258.html
61 .. _Python: http://www.python.org/
64 Why is it called "Docutils"?
65 ----------------------------
67 Docutils is short for "Python Documentation Utilities".  The name
68 "Docutils" was inspired by "Distutils", the Python Distribution
69 Utilities architected by Greg Ward, a component of Python's standard
70 library.
72 The earliest known use of the term "docutils" in a Python context was
73 a `fleeting reference`__ in a message by Fred Drake on 1999-12-02 in
74 the Python Doc-SIG mailing list.  It was suggested `as a project
75 name`__ on 2000-11-27 on Doc-SIG, again by Fred Drake, in response to
76 a question from Tony "Tibs" Ibbs: "What do we want to *call* this
77 thing?".  This was shortly after David Goodger first `announced
78 reStructuredText`__ on Doc-SIG.
80 Tibs used the name "Docutils" for `his effort`__ "to document what the
81 Python docutils package should support, with a particular emphasis on
82 documentation strings".  Tibs joined the current project (and its
83 predecessors) and graciously donated the name.
85 For more history of reStructuredText and the Docutils project, see `An
86 Introduction to reStructuredText`_.
88 Please note that the name is "Docutils", not "DocUtils" or "Doc-Utils"
89 or any other variation.
91 .. _An Introduction to reStructuredText:
92    http://docutils.sourceforge.net/docs/ref/rst/introduction.html
93 __ http://mail.python.org/pipermail/doc-sig/1999-December/000878.html
94 __ http://mail.python.org/pipermail/doc-sig/2000-November/001252.html
95 __ http://mail.python.org/pipermail/doc-sig/2000-November/001239.html
96 __ http://homepage.ntlworld.com/tibsnjoan/docutils/STpy.html
99 Is there a GUI authoring environment for Docutils?
100 --------------------------------------------------
102 DocFactory_ is under development.  It uses wxPython and looks very
103 promising.
105 .. _DocFactory:
106    http://docutils.sf.net/sandbox/gschwant/docfactory/doc/
109 What is the status of the Docutils project?
110 -------------------------------------------
112 Although useful and relatively stable, Docutils is experimental code,
113 with APIs and architecture subject to change.
115 Our highest priority is to fix bugs as they are reported.  So the
116 latest code from CVS (or `development snapshots`_) is almost always
117 the most stable (bug-free) as well as the most featureful.
120 What is the Docutils project release policy?
121 --------------------------------------------
123 It's "release early & often".  We also have automatically-generated
124 `development snapshots`_ which always contain the latest code from
125 CVS.  As the project matures, we may formalize on a
126 stable/development-branch scheme, but we're not using anything like
127 that yet.
129 .. _development snapshots:
130    http://docutils.sourceforge.net/#development-snapshots
133 reStructuredText
134 ================
136 What is reStructuredText?
137 -------------------------
139 reStructuredText_ is an easy-to-read, what-you-see-is-what-you-get
140 plaintext markup syntax and parser system.  The reStructuredText
141 parser is a component of Docutils_.  reStructuredText is a revision
142 and reinterpretation of the StructuredText_ and Setext_ lightweight
143 markup systems.
145 If you are reading this on the web, you can see for yourself.  `The
146 source for this FAQ <FAQ.txt>`_ is written in reStructuredText; open
147 it in another window and compare them side by side.
149 `A ReStructuredText Primer`_ and the `Quick reStructuredText`_ user
150 reference are a good place to start.  The `reStructuredText Markup
151 Specification`_ is a detailed technical specification.
153 .. _A ReStructuredText Primer:
154    http://docutils.sourceforge.net/docs/user/rst/quickstart.html
155 .. _Quick reStructuredText:
156    http://docutils.sourceforge.net/docs/user/rst/quickref.html
157 .. _reStructuredText Markup Specification:
158    http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
159 .. _reStructuredText: http://docutils.sourceforge.net/rst.html
160 .. _StructuredText:
161    http://dev.zope.org/Members/jim/StructuredTextWiki/FrontPage/
162 .. _Setext: http://docutils.sourceforge.net/mirror/setext.html
165 Why is it called "reStructuredText"?
166 ------------------------------------
168 The name came from a combination of "StructuredText", one of
169 reStructuredText's predecessors, with "re": "revised", "reworked", and
170 "reinterpreted", and as in the ``re.py`` regular expression module.
171 For a detailed history of reStructuredText and the Docutils project,
172 see `An Introduction to reStructuredText`_.
175 What's the standard abbreviation for "reStructuredText"?
176 --------------------------------------------------------
178 "RST" and "ReST" (or "reST") are both acceptable.  Care should be
179 taken with capitalization, to avoid confusion with "REST__", an
180 acronym for "Representational State Transfer".
182 The abbreviations "reSTX" and "rSTX"/"rstx" should **not** be used;
183 they overemphasize reStructuredText's precedessor, Zope's
184 StructuredText.
186 __ http://www.xml.com/pub/a/2002/02/06/rest.html
189 What's the standard filename extension for a reStructuredText file?
190 -------------------------------------------------------------------
192 It's ".txt".  Some people would like to use ".rest" or ".rst" or
193 ".restx", but why bother?  ReStructuredText source files are meant to
194 be readable as plaintext, and most operating systems already associate
195 ".txt" with text files.  Using a specialized filename extension would
196 require that users alter their OS settings, which is something that
197 many users will not be willing or able to do.
200 Are there any reStructuredText editor extensions?
201 -------------------------------------------------
203 See `Editor Support for reStructuredText`__.
205 __ http://docutils.sf.net/tools/editors/README.html
208 How can I indicate the document title?  Subtitle?
209 -------------------------------------------------
211 A uniquely-adorned section title at the beginning of a document is
212 treated specially, as the document title.  Similarly, a
213 uniquely-adorned section title immediately after the document title
214 becomes the document subtitle.  For example::
216     This is the Document Title
217     ==========================
219     This is the Document Subtitle
220     -----------------------------
222     Here's an ordinary paragraph.
224 Counterexample::
226     Here's an ordinary paragraph.
228     This is *not* a Document Title
229     ==============================
231     The "ordinary paragraph" above the section title
232     prevents it from becoming the document title.
234 Another counterexample::
236     This is not the Document Title,  because...
237     ===========================================
239     Here's an ordinary paragraph.
241     ... the title adornment is not unique
242     =====================================
244     Another ordinary paragraph.
247 How can I represent esoteric characters (e.g. character entities) in a document?
248 --------------------------------------------------------------------------------
250 For example, say you want an em-dash (XML character entity &mdash;,
251 Unicode character U+2014) in your document: use a real em-dash.
252 Insert concrete characters (e.g. type a *real* em-dash) into your
253 input file, using whatever encoding suits your application, and tell
254 Docutils the input encoding.  Docutils uses Unicode internally, so the
255 em-dash character is a real em-dash internally.
257 Emacs users should refer to the `Emacs Support for reStructuredText`__
258 document.  Tips for other editors are welcome.
260 __ http://docutils.sourceforge.net/tools/editors/emacs/README.html
262 ReStructuredText has no character entity subsystem; it doesn't know
263 anything about XML charents.  To Docutils, "&mdash;" in input text is
264 7 discrete characters; no interpretation happens.  When writing HTML,
265 the "&" is converted to "&amp;", so in the raw output you'd see
266 "&amp;mdash;".  There's no difference in interpretation for text
267 inside or outside inline literals or literal blocks -- there's no
268 character entity interpretation in either case.
270 If you can't use a Unicode-compatible encoding and must rely on 7-bit
271 ASCII, there is a workaround.  Files containing character entity set
272 substitution definitions using the "unicode_" directive `are
273 available`_ (tarball_).  Please read the `description and
274 instructions`_ for use.  Thanks to David Priest for the original idea.
275 Incorporating these files into Docutils is on the `to-do list`_.
276    
277 If you insist on using XML-style charents, you'll have to implement a
278 pre-processing system to convert to UTF-8 or something.  That
279 introduces complications though; you can no longer *write* about
280 charents naturally; instead of writing "&mdash;" you'd have to write
281 "&amp;mdash;".
283 For the common case of long dashes, you might also want to insert the
284 following substitution definitons into your document (both of them are
285 using the "unicode_" directive)::
287     .. |--| unicode:: U+2013   .. en dash
288     .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
289        :trim:
291 .. |--| unicode:: U+2013   .. en dash
292 .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
293    :trim:
295 Now you can write dashes using pure ASCII: "``foo |--| bar; foo |---|
296 bar``", rendered as "foo |--| bar; foo |---| bar".  (Note that Mozilla
297 and Firefox may render this incorrectly.)  The ``:trim:`` option for
298 the em dash is necessary because you cannot write "``foo|---|bar``";
299 thus you need to add spaces ("``foo |---| bar``") and advise the
300 reStructuredText parser to trim the spaces using the ``:trim:``
301 option.
303 .. _unicode:
304    http://docutils.sf.net/docs/ref/rst/directives.html#unicode-character-codes
305 .. _are available: http://docutils.sourceforge.net/tmp/charents/
306 .. _tarball: http://docutils.sourceforge.net/tmp/charents.tgz
307 .. _description and instructions:
308    http://docutils.sourceforge.net/tmp/charents/README.html
309 .. _to-do list: http://docutils.sourceforge.net/docs/dev/todo.html
312 How can I generate backticks using a Scandinavian keyboard?
313 -----------------------------------------------------------
315 The use of backticks in reStructuredText is a bit awkward with
316 Scandinavian keyboards, where the backtick is a "dead" key.  To get
317 one ` character one must press SHIFT-` + SPACE.
319 Unfortunately, with all the variations out there, there's no way to
320 please everyone.  For Scandinavian programmers and technical writers,
321 this is not limited to reStructuredText but affects many languages and
322 environments.
324 Possible solutions include
326 * If you have to input a lot of backticks, simply type one in the
327   normal/awkward way, select it, copy and then paste the rest (CTRL-V
328   is a lot faster than SHIFT-` + SPACE).
330 * Use keyboard macros.
332 * Remap the keyboard.  The Scandinavian keyboard layout is awkward for
333   other programming/technical characters too; for example, []{}
334   etc. are a bit awkward compared to US keyboards.
336   According to Axel Kollmorgen,
338       Under Windows, you can use the `Microsoft Keyboard Layout Creator
339       <http://www.microsoft.com/globaldev/tools/msklc.mspx>`__ to easily
340       map the backtick key to a real backtick (no dead key). took me
341       five minutes to load my default (german) keyboard layout, untick
342       "Dead Key?" from the backtick key properties ("in all shift
343       states"), "build dll and setup package", install the generated
344       .msi, and add my custom keyboard layout via Control Panel >
345       Regional and Language Options > Languages > Details > Add
346       Keyboard layout (and setting it as default "when you start your
347       computer").
349 * Use a virtual/screen keyboard or character palette, such as:
351   - `Web-based keyboards <http://keyboard.lab.co.il/>`__ (IE only
352     unfortunately).
353   - Windows: `Click-N-Type <http://www.lakefolks.org/cnt/>`__.
354   - Mac OS X: the Character Palette can store a set of favorite
355     characters for easy input.  Open System Preferences,
356     International, Input Menu tab, enable "Show input menu in menu
357     bar", and be sure that Character Palette is enabled in the list.
359   Other options are welcome.
361 If anyone knows of other/better solutions, please `let us know`_.
364 Are there any tools for HTML/XML-to-reStructuredText?  (Round-tripping)
365 -----------------------------------------------------------------------
367 People have tossed the idea around, but little if any actual work has
368 ever been done.  There's no reason why reStructuredText should not be
369 round-trippable to/from XML; any technicalities which prevent
370 round-tripping would be considered bugs.  Whitespace would not be
371 identical, but paragraphs shouldn't suffer.  The tricky parts would be
372 the smaller details, like links and IDs and other bookkeeping.
374 For HTML, true round-tripping may not be possible.  Even adding lots
375 of extra "class" attributes may not be enough.  A "simple HTML" to RST
376 filter is possible -- for some definition of "simple HTML" -- but HTML
377 is used as dumb formatting so much that such a filter may not be
378 particularly useful.  No general-purpose filter exists.  An 80/20
379 approach should work though: build a tool that does 80% of the work
380 automatically, leaving the other 20% for manual tweaks.
383 Are there any Wikis that use reStructuredText syntax?
384 -----------------------------------------------------
386 There are several, with various degrees of completeness.  With no
387 implied endorsement or recommendation, and in no particular order:
389 * `Ian Bicking's experimental code
390   <http://docutils.sf.net/sandbox/ianb/wiki/WikiPage.py>`__
391 * `MoinMoin <http://moin.sf.net>`__ has some support; `here's a sample
392   <http://twistedmatrix.com/users/jh.twistd/moin/moin.cgi/RestSample>`__
393 * Zope-based `Zwiki <http://zwiki.org/>`__
394 * Zope3-based Zwiki (in the Zope 3 source tree as ``zope.products.zwiki``)
395 * `StikiWiki <http://mithrandr.moria.org/code/stikiwiki/>`__
396 * `Trac <http://projects.edgewall.com/trac/>`__ `supports using reStructuredText
397   <http://projects.edgewall.com/trac/wiki/WikiRestructuredText>`__ as an
398   alternative to wiki markup. This includes support for `TracLinks
399   <http://projects.edgewall.com/trac/wiki/TracLinks>`__ from within RST
400   text via a custom RST reference-directive or, even easier, an interpreted text
401   role 'trac'
402 * `Vogontia <http://www.ososo.de/vogontia/>`__, a Wiki-like FAQ system
404 Please `let us know`_ of any other reStructuredText Wikis.
406 The example application for the `Web Framework Shootout
407 <http://colorstudy.com/docs/shootout.html>`__ article is a Wiki using
408 reStructuredText.
411 Are there any Weblog (Blog) projects that use reStructuredText syntax?
412 ----------------------------------------------------------------------
414 With no implied endorsement or recommendation, and in no particular
415 order:
417 * `Python Desktop Server <http://pyds.muensterland.org/>`__
418 * `PyBloxsom <http://roughingit.subtlehints.net/pyblosxom/>`__
419 * `rst2ht <http://www.rutherfurd.net/articles/rst-ht2html.html>`__
420 * `htmlnav <http://docutils.sourceforge.net/sandbox/gschwant/htmlnav/>`__
421 * `restblog <http://docutils.sourceforge.net/sandbox/mly/restblog/>`__
422 * `ReSTWeb <http://wingide.com/opensource/restweb>`__
423 * `Lino WebMan <http://lino.sourceforge.net/webman.html>`__
425 Please `let us know`_ of any other reStructuredText Blogs.
428 Can lists be indented without generating block quotes?
429 ------------------------------------------------------
431 Some people like to write lists with indentation, without intending a
432 block quote context, like this::
434     paragraph
436       * list item 1
437       * list item 2
439 There has been a lot of discussion about this, but there are some
440 issues that would need to be resolved before it could be implemented.
441 There is a summary of the issues and pointers to the discussions in
442 `the to-do list`__.
444 __ http://docutils.sourceforge.net/docs/dev/todo.html#indented-lists
447 Could the requirement for blank lines around lists be relaxed?
448 --------------------------------------------------------------
450 Short answer: no.
452 In reStructuredText, it would be impossible to unambigously mark up
453 and parse lists without blank lines before and after.  Deeply nested
454 lists may look ugly with so many blank lines, but it's a price we pay
455 for unambiguous markup.  Some other plaintext markup systems do not
456 require blank lines in nested lists, but they have to compromise
457 somehow, either accepting ambiguity or requiring extra complexity.
458 For example, `Epytext <http://epydoc.sf.net/epytext.html#list>`__ does
459 not require blank lines around lists, but it does require that lists
460 be indented and that ambiguous cases be escaped.
463 How can I include mathematical equations in documents?
464 ------------------------------------------------------
466 There is no elegant built-in way, yet.  There are several ideas, but
467 no obvious winner.  This issue requires a champion to solve the
468 technical and aesthetic issues and implement a generic solution.
469 Here's the `to-do list entry`__.
471 __ http://docutils.sourceforge.net/docs/dev/todo.html#math-markup
473 There are several quick & dirty ways to include equations in documents.
474 They all presently use LaTeX syntax or dialects of it.
476 * For LaTeX output, nothing beats raw LaTeX math.  A simple way is to
477   use the `raw directive`_::
479       .. raw:: latex
481           \[ x^3 + 3x^2a + 3xa^2 + a^3, \]
482           
483   For inline math you could use substitutions of the raw directive but
484   the recently added `raw role`_ is more convenient.  You must define a
485   custom role based on it once in your document::
487       .. role:: raw-latex(raw)
488           :format: latex
490   and then you can just use the new role in your text::
492       the binomial expansion of :raw-latex:`$(x+a)^3$` is
494   .. _raw directive: http://docutils.sourceforge.net/docs/ref/rst/
495                      directives.html#raw-data-pass-through
496   .. _raw role: http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw
498 * For HTML the "Right" w3c-standard way to include math is MathML_.
499   Unfortunately its rendering is still quite broken (or absent) on many
500   browsers but it's getting better.  Another bad problem is that typing
501   or reading raw MathML by humans is *really* painful, so embedding it
502   in a reST document with the raw directive would defy the goals of
503   readability and editability of reST (see an `example of raw MathML
504   <http://sf.net/mailarchive/message.php?msg_id=2177102>`__).
506   A much less painful way to generate HTML+MathML is to use itex2mml_ to
507   convert a dialect of LaTeX syntax to presentation MathML.  Here is an
508   example of potential `itex math markup
509   <http://article.gmane.org/gmane.text.docutils.user/118>`__.  The
510   simplest way to use it is to add ``html`` to the format lists for the
511   raw directive/role and postprocess the resulting document with
512   itex2mml.  This way you can *generate LaTeX and HTML+MathML from the
513   same source*, but you must limit yourself to the intersection of LaTeX
514   and itex markups for this to work.  Alan G. Isaac wrote a detailed
515   HOWTO_ for this approach.
517   .. _MathML: http://www.w3.org/Math/
518   .. _itex2mml: http://pear.math.pitt.edu/mathzilla/itex2mml.html
519   .. _HOWTO: http://www.american.edu/econ/itex2mml/mathhack.rst
521   * The other way to add math to HTML is to use images of the equations,
522     typically generated by TeX.  This is inferior to MathML in the long
523     term but is perhaps more accessible nowdays.
525     Of course, doing it by hand is too much work.  Beni Cherniavsky has
526     written some `preprocessing scripts`__ for converting the
527     ``texmath`` role/directive into images for HTML output and raw
528     directives/subsitution for LaTeX output.  This way you can *generate
529     LaTeX and HTML+images from the same source*.  `Instructions here`__.
531     __ http://docutils.sourceforge.net/sandbox/cben/rolehack/
532     __ http://docutils.sourceforge.net/sandbox/cben/rolehack/README.html
535 Is nested inline markup possible?
536 ---------------------------------
538 Not currently, no.  It's on the `to-do list`__ (`details here`__), and
539 hopefully will be part of the reStructuredText parser soon.  At that
540 time, markup like this will become possible::
542     Here is some *emphasized text containing a `hyperlink`_ and
543     ``inline literals``*.
545 __ http://docutils.sf.net/docs/dev/todo.html#nested-inline-markup
546 __ http://docutils.sf.net/docs/dev/rst/alternatives.html#nested-inline-markup
548 There are workarounds, but they are either convoluted or ugly or both.
549 They are not recommended.
551 * Inline markup can be combined with hyperlinks using `substitution
552   definitions`__ and references__ with the `"replace" directive`__.
553   For example::
555       Here is an |emphasized hyperlink|_.
557       .. |emphasized hyperlink| replace:: *emphasized hyperlink*
558       .. _emphasized hyperlink: http://example.org
560   It is not possible for just a portion of the replacement text to be
561   a hyperlink; it's the entire replacement text or nothing.
563   __ http://docutils.sf.net/docs/ref/rst/restructuredtext.html#substitution-definitions
564   __ http://docutils.sf.net/docs/ref/rst/restructuredtext.html#substitution-references
565   __ http://docutils.sf.net/docs/ref/rst/directives.html#replace
567 * The `"raw" directive`__ can be used to insert raw HTML into HTML
568   output::
570       Here is some |stuff|.
572       .. |stuff| raw:: html
574          <em>emphasized text containing a
575          <a href="http://example.org">hyperlink</a> and
576          <tt>inline literals</tt></em>
578   Raw LaTeX is supported for LaTeX output, etc.
580   __ http://docutils.sf.net/docs/ref/rst/directives.html#raw
583 How to indicate a line break or a significant newline?
584 ------------------------------------------------------
586 `Line blocks`__ are designed for address blocks, verse, and other
587 cases where line breaks are significant and must be preserved.  Unlike
588 literal blocks, the typeface is not changed, and inline markup is
589 recognized.  For example::
591     | A one, two, a one two three four
592     | 
593     | Half a bee, philosophically,
594     |     must, *ipso facto*, half not be.
595     | But half the bee has got to be,
596     |     *vis a vis* its entity.  D'you see?
597     | 
598     | But can a bee be said to be
599     |     or not to be an entire bee,
600     |         when half the bee is not a bee,
601     |             due to some ancient injury?
602     | 
603     | Singing...
605 __ http://docutils.sf.net/docs/ref/rst/restructuredtext.html#line-blocks
607 Here's a workaround for manually inserting explicit line breaks in
608 HTML output::
610     .. |br| raw:: html
612        <br />
614     I want to break this line here: |br| this is after the break.
616     If the extra whitespace bothers you, |br|\ backslash-escape it.
619 A URL containing asterisks doesn't work.  What to do?
620 -----------------------------------------------------
622 Asterisks are valid URL characters (see :RFC:`2396`), sometimes used
623 in URLs.  For example::
625     http://cvs.example.org/viewcvs.py/*checkout*/module/file
627 Unfortunately, the parser thinks the asterisks are indicating
628 emphasis.  The slashes serve as delineating punctuation, allowing the
629 asterisks to be recognized as markup.  The example above is separated
630 by the parser into a truncated URL, an emphasized word, and some
631 regular text::
633     http://cvs.example.org/viewcvs.py/
634     *checkout*
635     /module/file
637 To turn off markup recognition, use a backslash to escape at least the
638 first asterisk, like this::
640     http://cvs.example.org/viewcvs.py/\*checkout*/module/file
642 Escaping the second asterisk doesn't hurt, but it isn't necessary.
645 How can I make a literal block with *some* formatting?
646 ------------------------------------------------------
648 Use the `parsed-literal`_ directive.
650 .. _parsed-literal: docs/ref/rst/directives.html#parsed-literal
652 Scenario: a document contains some source code, which calls for a
653 literal block to preserve linebreaks and whitespace.  But part of the
654 source code should be formatted, for example as emphasis or as a
655 hyperlink.  This calls for a *parsed* literal block::
657     .. parsed-literal::
659        print "Hello world!"  # *tricky* code [1]_
661 The emphasis (``*tricky*``) and footnote reference (``[1]_``) will be
662 parsed.
665 Can reStructuredText be used for web or generic templating?
666 -----------------------------------------------------------
668 Docutils and reStructuredText can be used with or as a component of a
669 templating system, but they do not themselves include templating
670 functionality.  Templating should simply be left to dedicated
671 templating systems.  Users can choose a templating system to apply to
672 their reStructuredText documents as best serves their interests.
674 There are many good templating systems for Python (ht2html_, YAPTU_,
675 Quixote_'s PTL, Cheetah_, etc.; see this non-exhaustive list of `some
676 other templating systems`_), and many more for other languages, each
677 with different approaches.  We invite you to try several and find one
678 you like.  If you adapt it to use Docutils/reStructuredText, please
679 consider contributing the code to Docutils or `let us know`_ and we'll
680 keep a list here.
682 .. _ht2html: http://ht2html.sourceforge.net/
683 .. _YAPTU:
684    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305
685 .. _Quixote: http://www.mems-exchange.org/software/quixote/
686 .. _Cheetah: http://www.cheetahtemplate.org/
687 .. _some other templating systems:
688    http://webware.sourceforge.net/Papers/Templates/
691 HTML Writer
692 ===========
694 What is the status of the HTML Writer?
695 --------------------------------------
697 The HTML Writer module, ``docutils/writers/html4css1.py``, is a
698 proof-of-concept reference implementation.  While it is a complete
699 implementation, some aspects of the HTML it produces may be
700 incompatible with older browsers or specialized applications (such as
701 web templating).  Alternate implementations are welcome.
704 What kind of HTML does it produce?
705 ----------------------------------
707 It produces XHTML compatible with the `HTML 4.01`_ and `XHTML 1.0`_
708 specifications (within reason; there are some incompatibilities
709 between the specs).  A cascading style sheet ("default.css" by
710 default) is required for proper viewing with a modern graphical
711 browser.  Correct rendering of the HTML produced depends on the CSS
712 support of the browser.
714 .. _HTML 4.01: http://www.w3.org/TR/html4/
715 .. _XHTML 1.0: http://www.w3.org/TR/xhtml1/
718 What browsers are supported?
719 ----------------------------
721 No specific browser is targeted; all modern graphical browsers should
722 work.  Some older browsers, text-only browsers, and browsers without
723 full CSS support are known to produce inferior results.  Firefox,
724 Safari, Mozilla (version 1.0 and up), and MS Internet Explorer
725 (version 5.0 and up) are known to give good results.  Reports of
726 experiences with other browsers are welcome.
729 Unexpected results from tools/rst2html.py: H1, H1 instead of H1, H2.  Why?
730 --------------------------------------------------------------------------
732 Here's the question in full:
734     I have this text::
736         Heading 1
737         =========
739         All my life, I wanted to be H1.
741         Heading 1.1
742         -----------
744         But along came H1, and so shouldn't I be H2?
745         No!  I'm H1!
747         Heading 1.1.1
748         *************
750         Yeah, imagine me, I'm stuck at H3!  No?!?
752     When I run it through tools/rst2html.py, I get unexpected results
753     (below).  I was expecting H1, H2, then H3; instead, I get H1, H1,
754     H2::
756         ...
757         <html lang="en">
758         <head>
759         ...
760         <title>Heading 1</title>
761         <link rel="stylesheet" href="default.css" type="text/css" />
762         </head>
763         <body>
764         <div class="document" id="heading-1">
765         <h1 class="title">Heading 1</h1>                <-- first H1
766         <p>All my life, I wanted to be H1.</p>
767         <div class="section" id="heading-1-1">
768         <h1><a name="heading-1-1">Heading 1.1</a></h1>        <-- H1
769         <p>But along came H1, and so now I must be H2.</p>
770         <div class="section" id="heading-1-1-1">
771         <h2><a name="heading-1-1-1">Heading 1.1.1</a></h2>
772         <p>Yeah, imagine me, I'm stuck at H3!</p>
773         ...
775     What gives?
777 Check the "class" attribute on the H1 tags, and you will see a
778 difference.  The first H1 is actually ``<h1 class="title">``; this is
779 the document title, and the default stylesheet renders it centered.
780 There can also be an ``<h2 class="subtitle">`` for the document
781 subtitle.
783 If there's only one highest-level section title at the beginning of a
784 document, it is treated specially, as the document title.  (Similarly, a
785 lone second-highest-level section title may become the document
786 subtitle.)  See `How can I indicate the document title?  Subtitle?`_ for
787 details.  Rather than use a plain H1 for the document title, we use ``<h1
788 class="title">`` so that we can use H1 again within the document.  Why
789 do we do this?  HTML only has H1-H6, so by making H1 do double duty, we
790 effectively reserve these tags to provide 6 levels of heading beyond the
791 single document title.
793 HTML is being used for dumb formatting for nothing but final display.
794 A stylesheet *is required*, and one is provided:
795 tools/stylesheets/default.css.  Of course, you're welcome to roll your
796 own.  The default stylesheet provides rules to format ``<h1
797 class="title">`` and ``<h2 class="subtitle">`` differently from
798 ordinary ``<h1>`` and ``<h2>``::
800     h1.title {
801       text-align: center }
803     h2.subtitle {
804       text-align: center }
806 If you don't want the top section heading to be interpreted as a
807 title at all, disable the `doctitle_xform`_ setting
808 (``--no-doc-title`` option).  This will interpret your document
809 differently from the standard settings, which might not be a good
810 idea.  If you don't like the reuse of the H1 in the HTML output, you
811 can tweak the `initial_header_level`_ setting
812 (``--initial-header-level`` option) -- but unless you match its value
813 to your specific document, you might end up with bad HTML (e.g. H3
814 without H2).
816 .. _doctitle_xform:
817    http://docutils.sourceforge.net/docs/user/config.html#doctitle-xform
818 .. _initial_header_level:
819    http://docutils.sourceforge.net/docs/user/config.html#initial-header-level
821 (Thanks to Mark McEahern for the question and much of the answer.)
824 Why do enumerated lists only use numbers (no letters or roman numerals)?
825 ------------------------------------------------------------------------
827 The rendering of enumerators (the numbers or letters acting as list
828 markers) is completely governed by the stylesheet, so either the
829 browser can't find the stylesheet (try using the "--embed-stylesheet"
830 option), or the browser can't understand it (try a recent Firefox,
831 Mozilla, Konqueror, Opera, Safari, or even MSIE).
834 There appear to be garbage characters in the HTML.  What's up?
835 --------------------------------------------------------------
837 What you're seeing is most probably not garbage, but the result of a
838 mismatch between the actual encoding of the HTML output and the
839 encoding your browser is expecting.  Your browser is misinterpreting
840 the HTML data, which is encoded text.  A discussion of text encodings
841 is beyond the scope of this FAQ; see one or more of these documents
842 for more info:
844 * `UTF-8 and Unicode FAQ for Unix/Linux
845   <http://www.cl.cam.ac.uk/~mgk25/unicode.html>`_
847 * Chapters 3 and 4 of `Introduction to i18n [Internationalization]
848   <http://www.debian.org/doc/manuals/intro-i18n/>`_
850 * `Python Unicode Tutorial
851   <http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
853 * `Python Unicode Objects: Some Observations on Working With Non-ASCII
854   Character Sets <http://effbot.org/zone/unicode-objects.htm>`_
856 The common case is with the default output encoding (UTF-8), when
857 either numbered sections are used (via the "sectnum_" directive) or
858 symbol-footnotes.  3 non-breaking spaces are inserted in each numbered
859 section title, between the generated number and the title text.  Most
860 footnote symbols are not available in ASCII, nor are non-breaking
861 spaces.  When encoded with UTF-8 and viewed with ordinary ASCII tools,
862 these characters will appear to be multi-character garbage.
864 You may have an decoding problem in your browser (or editor, etc.).
865 The encoding of the output is set to "utf-8", but your browswer isn't
866 recognizing that.  You can either try to fix your browser (enable
867 "UTF-8 character set", sometimes called "Unicode"), or choose a
868 different encoding for the HTML output.  You can also try
869 ``--output-encoding=ascii:xmlcharrefreplace`` for HTML (not applicable
870 to non-XMLish outputs).
872 If you're generating document fragments, the "Content-Type" metadata
873 (between the HTML ``<head>`` and ``</head>`` tags) must agree with the
874 encoding of the rest of the document.  For UTF-8, it should be::
876     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
878 Also, Docutils normally generates an XML declaration as the first line
879 of the output.  It must also match the document encoding.  For UTF-8::
881     <?xml version="1.0" encoding="utf-8" ?>
883 .. _sectnum:
884    http://docutils.sourceforge.net/docs/ref/rst/directives.html#sectnum
887 Python Source Reader
888 ====================
890 Can I use Docutils for Python auto-documentation?
891 -------------------------------------------------
893 Yes, in conjunction with other projects.
895 Docstring extraction functionality from within Docutils is still under
896 development.  There is most of a source code parsing module in
897 docutils/readers/python/moduleparser.py.  We do plan to finish it
898 eventually.  Ian Bicking wrote an initial front end for the
899 moduleparser.py module, in sandbox/ianb/extractor/extractor.py.  Ian
900 also did some work on the Python Source Reader
901 (docutils.readers.python) component at PyCon DC 2004.
903 Version 2.0 of Ed Loper's `Epydoc <http://epydoc.sourceforge.net/>`_
904 supports reStructuredText-format docstrings for HTML output.  Docutils
905 0.3 or newer is required.  Development of a Docutils-specific
906 auto-documentation tool will continue.  Epydoc works by importing
907 Python modules to be documented, whereas the Docutils-specific tool,
908 described above, will parse modules without importing them (as with
909 `HappyDoc <http://happydoc.sourceforge.net/>`_, which doesn't support
910 reStructuredText).
912 The advantages of parsing over importing are security and flexibility;
913 the disadvantage is complexity/difficulty.
915 * Security: untrusted code that shouldn't be executed can be parsed;
916   importing a module executes its top-level code.
917 * Flexibility: comments and unofficial docstrings (those not supported
918   by Python syntax) can only be processed by parsing.
919 * Complexity/difficulty: it's a lot harder to parse and analyze a
920   module than it is to ``import`` and analyze one.
922 For more details, please see "Docstring Extraction Rules" in `PEP
923 258`_, item 3 ("How").
926 Miscellaneous
927 =============
929 Is the Docutils document model based on any existing XML models?
930 ----------------------------------------------------------------
932 Not directly, no.  It borrows bits from DocBook, HTML, and others.  I
933 (David Goodger) have designed several document models over the years,
934 and have my own biases.  The Docutils document model is designed for
935 simplicity and extensibility, and has been influenced by the needs of
936 the reStructuredText markup.