~ubuntu-branches/ubuntu/karmic/python-docutils/karmic

« back to all changes in this revision

Viewing changes to FAQ.txt

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
=====================================
2
 
 Docutils Frequently Asked Questions
3
 
=====================================
4
 
 
5
 
:Date: $Date: 2004/04/15 13:42:50 $
 
1
.. -*- coding: utf-8 -*-
 
2
 
 
3
===========================================
 
4
 Docutils FAQ (Frequently Asked Questions)
 
5
===========================================
 
6
 
 
7
:Date: $Date: 2005-12-09 05:21:34 +0100 (Fri, 09 Dec 2005) $
 
8
:Revision: $Revision: 4163 $
6
9
:Web site: http://docutils.sourceforge.net/
7
10
:Copyright: This document has been placed in the public domain.
8
11
 
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.
13
 
 
14
 
 
15
12
.. contents::
16
13
.. sectnum::
17
14
 
18
15
 
19
16
This is a work in progress.  Please feel free to ask questions and/or
20
 
provide answers; `send email`__ to the `Docutils-Users mailing
21
 
list`__.  Project members should feel free to edit the source text
22
 
file directly.
 
17
provide answers; send email to the `Docutils-users`_ mailing list.
 
18
Project members should feel free to edit the source text file
 
19
directly.
23
20
 
24
21
.. _let us know:
25
 
__ mailto:docutils-users@lists.sourceforge.net
26
 
__ http://lists.sourceforge.net/lists/listinfo/docutils-users
 
22
.. _Docutils-users: docs/user/mailing-lists.html#docutils-users
27
23
 
28
24
 
29
25
Docutils
33
29
-----------------
34
30
 
35
31
Docutils_ is a system for processing plaintext documentation into
36
 
useful formats, such as HTML, XML, and TeX.  It supports multiple
 
32
useful formats, such as HTML, XML, and LaTeX.  It supports multiple
37
33
types of input, such as standalone files (implemented), inline
38
34
documentation from Python modules and packages (under development),
39
35
`PEPs (Python Enhancement Proposals)`_ (implemented), and others as
47
43
.. _Docutils: http://docutils.sourceforge.net/
48
44
.. _PEPs (Python Enhancement Proposals):
49
45
   http://www.python.org/peps/pep-0012.html
50
 
.. _PEP 258: spec/pep-0258.html
 
46
.. _PEP 258: http://www.python.org/peps/pep-0258.html
51
47
.. _Python: http://www.python.org/
52
48
 
53
49
 
78
74
Please note that the name is "Docutils", not "DocUtils" or "Doc-Utils"
79
75
or any other variation.
80
76
 
81
 
.. _An Introduction to reStructuredText: spec/rst/introduction.html
 
77
.. _An Introduction to reStructuredText:
 
78
   http://docutils.sourceforge.net/docs/ref/rst/introduction.html
82
79
__ http://mail.python.org/pipermail/doc-sig/1999-December/000878.html
83
80
__ http://mail.python.org/pipermail/doc-sig/2000-November/001252.html
84
81
__ http://mail.python.org/pipermail/doc-sig/2000-November/001239.html
102
99
with APIs and architecture subject to change.
103
100
 
104
101
Our highest priority is to fix bugs as they are reported.  So the
105
 
latest code from CVS (or `development snapshots`_) is almost always
 
102
latest code from the repository_ (or the snapshots_) is almost always
106
103
the most stable (bug-free) as well as the most featureful.
107
104
 
108
105
 
109
106
What is the Docutils project release policy?
110
107
--------------------------------------------
111
108
 
112
 
It ought to be "release early & often", but official releases are a
113
 
significant effort and aren't done that often.  We have
114
 
automatically-generated `development snapshots`_ which always contain
115
 
the latest code from CVS.  As the project matures, we may formalize on
116
 
a stable/development-branch scheme, but we're not using anything like
 
109
It's "release early & often".  We also have automatically-generated
 
110
snapshots_ which always contain the latest code from the repository_.
 
111
As the project matures, we may formalize on a
 
112
stable/development-branch scheme, but we're not using anything like
117
113
that yet.
118
114
 
119
 
If anyone would like to volunteer as a release coordinator, please
120
 
`contact the project coordinator`_.
121
 
 
122
 
.. _development snapshots:
123
 
   http://docutils.sf.net/#development-snapshots
124
 
 
125
 
.. _contact the project coordinator:
126
 
   mailto:goodger@python.org
 
115
.. _repository: docs/dev/repository.html
 
116
.. _snapshots: http://docutils.sourceforge.net/#download
127
117
 
128
118
 
129
119
reStructuredText
142
132
source for this FAQ <FAQ.txt>`_ is written in reStructuredText; open
143
133
it in another window and compare them side by side.
144
134
 
145
 
`A ReStructuredText Primer <docs/rst/quickstart.html>`_ and the `Quick
146
 
reStructuredText <docs/rst/quickref.html>`_ user reference are a good
147
 
place to start.  The `reStructuredText Markup Specification
148
 
<spec/rst/reStructuredText.html>`_ is a detailed technical
149
 
specification.
 
135
`A ReStructuredText Primer`_ and the `Quick reStructuredText`_ user
 
136
reference are a good place to start.  The `reStructuredText Markup
 
137
Specification`_ is a detailed technical specification.
150
138
 
 
139
.. _A ReStructuredText Primer:
 
140
   http://docutils.sourceforge.net/docs/user/rst/quickstart.html
 
141
.. _Quick reStructuredText:
 
142
   http://docutils.sourceforge.net/docs/user/rst/quickref.html
 
143
.. _reStructuredText Markup Specification:
 
144
   http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
151
145
.. _reStructuredText: http://docutils.sourceforge.net/rst.html
152
146
.. _StructuredText:
153
147
   http://dev.zope.org/Members/jim/StructuredTextWiki/FrontPage/
154
 
.. _Setext: mirror/setext.html
 
148
.. _Setext: http://docutils.sourceforge.net/mirror/setext.html
155
149
 
156
150
 
157
151
Why is it called "reStructuredText"?
175
169
they overemphasize reStructuredText's precedessor, Zope's
176
170
StructuredText.
177
171
 
178
 
__ http://www.xml.com/pub/a/2002/02/06/rest.html
 
172
__ http://en.wikipedia.org/wiki/Representational_State_Transfer
179
173
 
180
174
 
181
175
What's the standard filename extension for a reStructuredText file?
192
186
Are there any reStructuredText editor extensions?
193
187
-------------------------------------------------
194
188
 
195
 
There is `some code under development for Emacs`__.
196
 
 
197
 
Extensions for other editors are welcome.
198
 
 
199
 
__ http://docutils.sf.net/tools/editors/emacs/
 
189
See `Editor Support for reStructuredText`__.
 
190
 
 
191
__ http://docutils.sf.net/tools/editors/README.html
200
192
 
201
193
 
202
194
How can I indicate the document title?  Subtitle?
225
217
    The "ordinary paragraph" above the section title
226
218
    prevents it from becoming the document title.
227
219
 
 
220
Another counterexample::
 
221
 
 
222
    This is not the Document Title,  because...
 
223
    ===========================================
 
224
 
 
225
    Here's an ordinary paragraph.
 
226
 
 
227
    ... the title adornment is not unique
 
228
    =====================================
 
229
 
 
230
    Another ordinary paragraph.
 
231
 
228
232
 
229
233
How can I represent esoteric characters (e.g. character entities) in a document?
230
234
--------------------------------------------------------------------------------
231
235
 
232
236
For example, say you want an em-dash (XML character entity &mdash;,
233
 
Unicode character ``\u2014``) in your document: use a real em-dash.
 
237
Unicode character U+2014) in your document: use a real em-dash.
234
238
Insert concrete characters (e.g. type a *real* em-dash) into your
235
239
input file, using whatever encoding suits your application, and tell
236
240
Docutils the input encoding.  Docutils uses Unicode internally, so the
237
241
em-dash character is a real em-dash internally.
238
242
 
 
243
Emacs users should refer to the `Emacs Support for reStructuredText`__
 
244
document.  Tips for other editors are welcome.
 
245
 
 
246
__ http://docutils.sourceforge.net/tools/editors/emacs/README.html
 
247
 
239
248
ReStructuredText has no character entity subsystem; it doesn't know
240
249
anything about XML charents.  To Docutils, "&mdash;" in input text is
241
250
7 discrete characters; no interpretation happens.  When writing HTML,
245
254
character entity interpretation in either case.
246
255
 
247
256
If you can't use a Unicode-compatible encoding and must rely on 7-bit
248
 
ASCII, there is a workaround.  Files containing character entity set
249
 
substitution definitions using the "unicode" directive `are available
250
 
<tmp/charents/>`__ (`tarball <tmp/charents.tgz>`__).  A description
251
 
and instructions for use `are here <tmp/charents/README.html>`__.
252
 
Thanks to David Priest for the original idea.  Incorporating these
253
 
files into Docutils is on the `to-do list <spec/notes.html#to-do>`_.
 
257
ASCII, there is a workaround.  New in Docutils 0.3.10 is a set of
 
258
`Standard Substitution Definition Sets`_, which provide equivalents of
 
259
XML & HTML character entity sets as substitution definitions.  For
 
260
example, the Japanese yen currency symbol can be used as follows::
 
261
 
 
262
    .. include:: <xhtml1-lat1.txt>
 
263
 
 
264
    |yen| 600 for a complete meal?  That's cheap!
 
265
 
 
266
For earlier versions of Docutils, equivalent files containing
 
267
character entity set substitution definitions using the "unicode_"
 
268
directive `are available`_.  Please read the `description and
 
269
instructions`_ for use.  Thanks to David Priest for the original idea.
254
270
 
255
271
If you insist on using XML-style charents, you'll have to implement a
256
272
pre-processing system to convert to UTF-8 or something.  That
258
274
charents naturally; instead of writing "&mdash;" you'd have to write
259
275
"&amp;mdash;".
260
276
 
 
277
For the common case of long dashes, you might also want to insert the
 
278
following substitution definitons into your document (both of them are
 
279
using the "unicode_" directive)::
 
280
 
 
281
    .. |--| unicode:: U+2013   .. en dash
 
282
    .. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
 
283
       :trim:
 
284
 
 
285
.. |--| unicode:: U+2013   .. en dash
 
286
.. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
 
287
   :trim:
 
288
 
 
289
Now you can write dashes using pure ASCII: "``foo |--| bar; foo |---|
 
290
bar``", rendered as "foo |--| bar; foo |---| bar".  (Note that Mozilla
 
291
and Firefox may render this incorrectly.)  The ``:trim:`` option for
 
292
the em dash is necessary because you cannot write "``foo|---|bar``";
 
293
thus you need to add spaces ("``foo |---| bar``") and advise the
 
294
reStructuredText parser to trim the spaces.
 
295
 
 
296
.. _Standard Substitution Definition Sets:
 
297
   http://docutils.sf.net/docs/ref/rst/substitutions.html
 
298
.. _unicode:
 
299
   http://docutils.sf.net/docs/ref/rst/directives.html#unicode-character-codes
 
300
.. _are available: http://docutils.sourceforge.net/tmp/charents/
 
301
.. _tarball: http://docutils.sourceforge.net/tmp/charents.tgz
 
302
.. _description and instructions:
 
303
   http://docutils.sourceforge.net/tmp/charents/README.html
 
304
.. _to-do list: http://docutils.sourceforge.net/docs/dev/todo.html
 
305
 
261
306
 
262
307
How can I generate backticks using a Scandinavian keyboard?
263
308
-----------------------------------------------------------
296
341
      Keyboard layout (and setting it as default "when you start your
297
342
      computer").
298
343
 
 
344
* Use a virtual/screen keyboard or character palette, such as:
 
345
 
 
346
  - `Web-based keyboards <http://keyboard.lab.co.il/>`__ (IE only
 
347
    unfortunately).
 
348
  - Windows: `Click-N-Type <http://www.lakefolks.org/cnt/>`__.
 
349
  - Mac OS X: the Character Palette can store a set of favorite
 
350
    characters for easy input.  Open System Preferences,
 
351
    International, Input Menu tab, enable "Show input menu in menu
 
352
    bar", and be sure that Character Palette is enabled in the list.
 
353
 
299
354
If anyone knows of other/better solutions, please `let us know`_.
300
355
 
301
356
 
302
357
Are there any tools for HTML/XML-to-reStructuredText?  (Round-tripping)
303
358
-----------------------------------------------------------------------
304
359
 
305
 
People have tossed the idea around, but little if any actual work has
306
 
ever been done.  There's no reason why reStructuredText should not be
307
 
round-trippable to/from XML; any technicalities which prevent
308
 
round-tripping would be considered bugs.  Whitespace would not be
309
 
identical, but paragraphs shouldn't suffer.  The tricky parts would be
310
 
the smaller details, like links and IDs and other bookkeeping.
 
360
People have tossed the idea around, and some implementations of
 
361
reStructuredText-generating tools can be found in the `Docutils Link
 
362
List`_.
 
363
 
 
364
There's no reason why reStructuredText should not be round-trippable
 
365
to/from XML; any technicalities which prevent round-tripping would be
 
366
considered bugs.  Whitespace would not be identical, but paragraphs
 
367
shouldn't suffer.  The tricky parts would be the smaller details, like
 
368
links and IDs and other bookkeeping.
311
369
 
312
370
For HTML, true round-tripping may not be possible.  Even adding lots
313
371
of extra "class" attributes may not be enough.  A "simple HTML" to RST
314
372
filter is possible -- for some definition of "simple HTML" -- but HTML
315
373
is used as dumb formatting so much that such a filter may not be
316
 
particularly useful.  No general-purpose filter exists.  An 80/20
317
 
approach should work though: build a tool that does 80% of the work
318
 
automatically, leaving the other 20% for manual tweaks.
 
374
particularly useful.  An 80/20 approach should work though: build a
 
375
tool that does 80% of the work automatically, leaving the other 20%
 
376
for manual tweaks.
 
377
 
 
378
.. _Docutils Link List: docs/user/links.html
319
379
 
320
380
 
321
381
Are there any Wikis that use reStructuredText syntax?
324
384
There are several, with various degrees of completeness.  With no
325
385
implied endorsement or recommendation, and in no particular order:
326
386
 
327
 
* `Ian Bicking's experimental code <sandbox/ianb/wiki/WikiPage.py>`__
328
 
* `MoinMoin <http://moin.sf.net>`__ has some support; `here's a sample
329
 
  <http://twistedmatrix.com/users/jh.twistd/moin/moin.cgi/RestSample>`__
 
387
* `Webware for Python wiki
 
388
  <http://wiki.webwareforpython.org/thiswiki.html>`__
 
389
* `Ian Bicking's experimental code
 
390
  <http://docutils.sf.net/sandbox/ianb/wiki/Wiki.py>`__
 
391
* `MoinMoin <http://moinmoin.wikiwikiweb.de/>`__ has some support;
 
392
  `here's a sample <http://moinmoin.wikiwikiweb.de/RestSample>`__
330
393
* Zope-based `Zwiki <http://zwiki.org/>`__
331
394
* Zope3-based Zwiki (in the Zope 3 source tree as ``zope.products.zwiki``)
332
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
333
403
 
334
404
Please `let us know`_ of any other reStructuredText Wikis.
335
405
 
344
414
With no implied endorsement or recommendation, and in no particular
345
415
order:
346
416
 
 
417
* `Firedrop <http://www.voidspace.org.uk/python/firedrop2/>`__
347
418
* `Python Desktop Server <http://pyds.muensterland.org/>`__
348
 
* `PyBloxsom <http://roughingit.subtlehints.net/pyblosxom>`__
349
 
* `rst2ht <http://www.rutherfurd.net/articles/rst-ht2html.html>`__
350
 
* `htmlnav <http://docutils.sourceforge.net/sandbox/gschwant/htmlnav/>`__
351
 
* `restblog <http://docutils.sourceforge.net/sandbox/mly/restblog/>`__
352
 
* `ReSTWeb <http://wingide.com/opensource/restweb>`__
 
419
* `PyBloxsom <http://roughingit.subtlehints.net/pyblosxom/>`__
353
420
* `Lino WebMan <http://lino.sourceforge.net/webman.html>`__
354
421
 
355
422
Please `let us know`_ of any other reStructuredText Blogs.
369
436
There has been a lot of discussion about this, but there are some
370
437
issues that would need to be resolved before it could be implemented.
371
438
There is a summary of the issues and pointers to the discussions in
372
 
`the to-do list
373
 
<http://docutils.sf.net/spec/notes.html#indented-lists>`__.
 
439
`the to-do list`__.
 
440
 
 
441
__ http://docutils.sourceforge.net/docs/dev/todo.html#indented-lists
374
442
 
375
443
 
376
444
Could the requirement for blank lines around lists be relaxed?
395
463
There is no elegant built-in way, yet.  There are several ideas, but
396
464
no obvious winner.  This issue requires a champion to solve the
397
465
technical and aesthetic issues and implement a generic solution.
398
 
Here's the `to-do list entry <spec/notes.html#math-markup>`__.
399
 
 
400
 
There are several quick & dirty ways to include equations in
401
 
documents:
402
 
 
403
 
* For HTML there is MathML but its rendering is still quite broken (or
404
 
  absent) on most browsers.  An example of raw MathML is `here
405
 
  <http://sf.net/mailarchive/message.php?msg_id=2177102>`__.
406
 
 
407
 
* If you use LaTeX output only, a simple way is to use the "raw"
408
 
  directive; examples are `here
409
 
  <http://article.gmane.org/gmane.text.docutils.devel/521>`__.
410
 
 
411
 
* Images of the equations can be used, typically generated by TeX.
412
 
  Beni Cherniavsky has written some `preprocessing scripts`__ for
413
 
  making inline TeX (for LaTeX and other [HTML etc.] output) math much
414
 
  easier; `instructions here`__.
 
466
Here's the `to-do list entry`__.
 
467
 
 
468
__ http://docutils.sourceforge.net/docs/dev/todo.html#math-markup
 
469
 
 
470
There are several quick & dirty ways to include equations in documents.
 
471
They all presently use LaTeX syntax or dialects of it.
 
472
 
 
473
* For LaTeX output, nothing beats raw LaTeX math.  A simple way is to
 
474
  use the `raw directive`_::
 
475
 
 
476
      .. raw:: latex
 
477
 
 
478
          \[ x^3 + 3x^2a + 3xa^2 + a^3, \]
 
479
 
 
480
  For inline math you could use substitutions of the raw directive but
 
481
  the recently added `raw role`_ is more convenient.  You must define a
 
482
  custom role based on it once in your document::
 
483
 
 
484
      .. role:: raw-latex(raw)
 
485
          :format: latex
 
486
 
 
487
  and then you can just use the new role in your text::
 
488
 
 
489
      the binomial expansion of :raw-latex:`$(x+a)^3$` is
 
490
 
 
491
  .. _raw directive: http://docutils.sourceforge.net/docs/ref/rst/
 
492
                     directives.html#raw-data-pass-through
 
493
  .. _raw role: http://docutils.sourceforge.net/docs/ref/rst/roles.html#raw
 
494
 
 
495
* Jens Jørgen Mortensen has implemented a "latex-math" role and
 
496
  directive, available from `his sandbox`__.
 
497
 
 
498
  __ http://docutils.sourceforge.net/sandbox/jensj/latex_math/
 
499
 
 
500
* For HTML the "Right" w3c-standard way to include math is MathML_.
 
501
  Unfortunately its rendering is still quite broken (or absent) on many
 
502
  browsers but it's getting better.  Another bad problem is that typing
 
503
  or reading raw MathML by humans is *really* painful, so embedding it
 
504
  in a reST document with the raw directive would defy the goals of
 
505
  readability and editability of reST (see an `example of raw MathML
 
506
  <http://sf.net/mailarchive/message.php?msg_id=2177102>`__).
 
507
 
 
508
  A much less painful way to generate HTML+MathML is to use itex2mml_ to
 
509
  convert a dialect of LaTeX syntax to presentation MathML.  Here is an
 
510
  example of potential `itex math markup
 
511
  <http://article.gmane.org/gmane.text.docutils.user/118>`__.  The
 
512
  simplest way to use it is to add ``html`` to the format lists for the
 
513
  raw directive/role and postprocess the resulting document with
 
514
  itex2mml.  This way you can *generate LaTeX and HTML+MathML from the
 
515
  same source*, but you must limit yourself to the intersection of LaTeX
 
516
  and itex markups for this to work.  Alan G. Isaac wrote a detailed
 
517
  HOWTO_ for this approach.
 
518
 
 
519
  .. _MathML: http://www.w3.org/Math/
 
520
  .. _itex2mml: http://pear.math.pitt.edu/mathzilla/itex2mml.html
 
521
  .. _HOWTO: http://www.american.edu/econ/itex2mml/mathhack.rst
 
522
 
 
523
* The other way to add math to HTML is to use images of the equations,
 
524
  typically generated by TeX.  This is inferior to MathML in the long
 
525
  term but is perhaps more accessible nowdays.
 
526
 
 
527
  Of course, doing it by hand is too much work.  Beni Cherniavsky has
 
528
  written some `preprocessing scripts`__ for converting the
 
529
  ``texmath`` role/directive into images for HTML output and raw
 
530
  directives/subsitution for LaTeX output.  This way you can *generate
 
531
  LaTeX and HTML+images from the same source*.  `Instructions here`__.
415
532
 
416
533
  __ http://docutils.sourceforge.net/sandbox/cben/rolehack/
417
534
  __ http://docutils.sourceforge.net/sandbox/cben/rolehack/README.html
418
535
 
419
 
* Here is an example of potential `itex math markup
420
 
  <http://article.gmane.org/gmane.text.docutils.user/118>`__.
 
536
 
 
537
Is nested inline markup possible?
 
538
---------------------------------
 
539
 
 
540
Not currently, no.  It's on the `to-do list`__ (`details here`__), and
 
541
hopefully will be part of the reStructuredText parser soon.  At that
 
542
time, markup like this will become possible::
 
543
 
 
544
    Here is some *emphasized text containing a `hyperlink`_ and
 
545
    ``inline literals``*.
 
546
 
 
547
__ http://docutils.sf.net/docs/dev/todo.html#nested-inline-markup
 
548
__ http://docutils.sf.net/docs/dev/rst/alternatives.html#nested-inline-markup
 
549
 
 
550
There are workarounds, but they are either convoluted or ugly or both.
 
551
They are not recommended.
 
552
 
 
553
* Inline markup can be combined with hyperlinks using `substitution
 
554
  definitions`__ and references__ with the `"replace" directive`__.
 
555
  For example::
 
556
 
 
557
      Here is an |emphasized hyperlink|_.
 
558
 
 
559
      .. |emphasized hyperlink| replace:: *emphasized hyperlink*
 
560
      .. _emphasized hyperlink: http://example.org
 
561
 
 
562
  It is not possible for just a portion of the replacement text to be
 
563
  a hyperlink; it's the entire replacement text or nothing.
 
564
 
 
565
  __ http://docutils.sf.net/docs/ref/rst/restructuredtext.html#substitution-definitions
 
566
  __ http://docutils.sf.net/docs/ref/rst/restructuredtext.html#substitution-references
 
567
  __ http://docutils.sf.net/docs/ref/rst/directives.html#replace
 
568
 
 
569
* The `"raw" directive`__ can be used to insert raw HTML into HTML
 
570
  output::
 
571
 
 
572
      Here is some |stuff|.
 
573
 
 
574
      .. |stuff| raw:: html
 
575
 
 
576
         <em>emphasized text containing a
 
577
         <a href="http://example.org">hyperlink</a> and
 
578
         <tt>inline literals</tt></em>
 
579
 
 
580
  Raw LaTeX is supported for LaTeX output, etc.
 
581
 
 
582
  __ http://docutils.sf.net/docs/ref/rst/directives.html#raw
 
583
 
 
584
 
 
585
How to indicate a line break or a significant newline?
 
586
------------------------------------------------------
 
587
 
 
588
`Line blocks`__ are designed for address blocks, verse, and other
 
589
cases where line breaks are significant and must be preserved.  Unlike
 
590
literal blocks, the typeface is not changed, and inline markup is
 
591
recognized.  For example::
 
592
 
 
593
    | A one, two, a one two three four
 
594
    |
 
595
    | Half a bee, philosophically,
 
596
    |     must, *ipso facto*, half not be.
 
597
    | But half the bee has got to be,
 
598
    |     *vis a vis* its entity.  D'you see?
 
599
    |
 
600
    | But can a bee be said to be
 
601
    |     or not to be an entire bee,
 
602
    |         when half the bee is not a bee,
 
603
    |             due to some ancient injury?
 
604
    |
 
605
    | Singing...
 
606
 
 
607
__ http://docutils.sf.net/docs/ref/rst/restructuredtext.html#line-blocks
 
608
 
 
609
Here's a workaround for manually inserting explicit line breaks in
 
610
HTML output::
 
611
 
 
612
    .. |br| raw:: html
 
613
 
 
614
       <br />
 
615
 
 
616
    I want to break this line here: |br| this is after the break.
 
617
 
 
618
    If the extra whitespace bothers you, |br|\ backslash-escape it.
 
619
 
 
620
 
 
621
A URL containing asterisks doesn't work.  What to do?
 
622
-----------------------------------------------------
 
623
 
 
624
Asterisks are valid URL characters (see :RFC:`2396`), sometimes used
 
625
in URLs.  For example::
 
626
 
 
627
    http://cvs.example.org/viewcvs.py/*checkout*/module/file
 
628
 
 
629
Unfortunately, the parser thinks the asterisks are indicating
 
630
emphasis.  The slashes serve as delineating punctuation, allowing the
 
631
asterisks to be recognized as markup.  The example above is separated
 
632
by the parser into a truncated URL, an emphasized word, and some
 
633
regular text::
 
634
 
 
635
    http://cvs.example.org/viewcvs.py/
 
636
    *checkout*
 
637
    /module/file
 
638
 
 
639
To turn off markup recognition, use a backslash to escape at least the
 
640
first asterisk, like this::
 
641
 
 
642
    http://cvs.example.org/viewcvs.py/\*checkout*/module/file
 
643
 
 
644
Escaping the second asterisk doesn't hurt, but it isn't necessary.
 
645
 
 
646
 
 
647
How can I make a literal block with *some* formatting?
 
648
------------------------------------------------------
 
649
 
 
650
Use the `parsed-literal`_ directive.
 
651
 
 
652
.. _parsed-literal: docs/ref/rst/directives.html#parsed-literal
 
653
 
 
654
Scenario: a document contains some source code, which calls for a
 
655
literal block to preserve linebreaks and whitespace.  But part of the
 
656
source code should be formatted, for example as emphasis or as a
 
657
hyperlink.  This calls for a *parsed* literal block::
 
658
 
 
659
    .. parsed-literal::
 
660
 
 
661
       print "Hello world!"  # *tricky* code [1]_
 
662
 
 
663
The emphasis (``*tricky*``) and footnote reference (``[1]_``) will be
 
664
parsed.
 
665
 
 
666
 
 
667
Can reStructuredText be used for web or generic templating?
 
668
-----------------------------------------------------------
 
669
 
 
670
Docutils and reStructuredText can be used with or as a component of a
 
671
templating system, but they do not themselves include templating
 
672
functionality.  Templating should simply be left to dedicated
 
673
templating systems.  Users can choose a templating system to apply to
 
674
their reStructuredText documents as best serves their interests.
 
675
 
 
676
There are many good templating systems for Python (ht2html_, YAPTU_,
 
677
Quixote_'s PTL, Cheetah_, etc.; see this non-exhaustive list of `some
 
678
other templating systems`_), and many more for other languages, each
 
679
with different approaches.  We invite you to try several and find one
 
680
you like.  If you adapt it to use Docutils/reStructuredText, please
 
681
consider contributing the code to Docutils or `let us know`_ and we'll
 
682
keep a list here.
 
683
 
 
684
One reST-specific web templating system is `rest2web
 
685
<http://www.voidspace.org.uk/python/rest2web>`_, a tool for
 
686
automatically building websites, or parts of websites.
 
687
 
 
688
.. _ht2html: http://ht2html.sourceforge.net/
 
689
.. _YAPTU:
 
690
   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305
 
691
.. _Quixote: http://www.mems-exchange.org/software/quixote/
 
692
.. _Cheetah: http://www.cheetahtemplate.org/
 
693
.. _some other templating systems:
 
694
   http://webware.sourceforge.net/Papers/Templates/
 
695
 
 
696
 
 
697
How can I mark up a FAQ or other list of questions & answers?
 
698
-------------------------------------------------------------
 
699
 
 
700
There is no specific syntax for FAQs and Q&A lists.  Here are two
 
701
options:
 
702
 
 
703
1. For a FAQ (Frequently Asked Questions, usually with answers), a
 
704
   convenient way to mark up the questions is as section titles, with
 
705
   the answer(s) as section content.  This document is marked up in
 
706
   this way.
 
707
 
 
708
   The advantages of using section titles for questions are: sections
 
709
   can be numbered automatically, and a table of contents can be
 
710
   generated automatically.  One limitation of this format is that
 
711
   questions must fit on one line (section titles may not wrap, in the
 
712
   source text).  For very long questions, the title may be a summary
 
713
   of the question, with the full question in the section body.
 
714
 
 
715
2. Field lists work well as Q&A lists::
 
716
 
 
717
       :Q: What kind of questions can we
 
718
           put here?
 
719
 
 
720
       :A: Any kind we like!
 
721
 
 
722
   In order to separate questions, lists can be used:
 
723
 
 
724
       1. :Q: What kind of question can we
 
725
              put here?
 
726
          :A: Any kind we like!
 
727
 
 
728
       2. :Q: How many answers can a question have?
 
729
          :A: It can have one,
 
730
          :A: or more.
 
731
          :A3: Answers can be numbered like this.
 
732
          :A: 1. Or like this.
 
733
              2. We're flexible!
 
734
 
 
735
   If you don't want to number or otherwise mark questions, you can
 
736
   use an empty comment between individual field lists to separate
 
737
   them::
 
738
 
 
739
       :Q: First question?
 
740
       :A: Answer.
 
741
 
 
742
       ..
 
743
 
 
744
       :Q: Second question?
 
745
       :A: Answer.
421
746
 
422
747
 
423
748
HTML Writer
436
761
What kind of HTML does it produce?
437
762
----------------------------------
438
763
 
439
 
It produces XHTML compatible with the `HTML 4.01`_ and `XHTML 1.0`_
440
 
specifications.  A cascading style sheet ("default.css" by default) is
441
 
required for proper viewing with a modern graphical browser.  Correct
442
 
rendering of the HTML produced depends on the CSS support of the
443
 
browser.
 
764
It produces XHTML compatible with the `XHTML 1.0`_ specification.  A
 
765
cascading stylesheet is required for proper viewing with a modern
 
766
graphical browser.  Correct rendering of the HTML produced depends on
 
767
the CSS support of the browser.  A general-purpose stylesheet,
 
768
``html4css1.css`` is provided with the code, and is embedded by
 
769
default.  It is installed in the "writers/html4css1/" subdirectory
 
770
within the Docutils package.  Use the ``--help`` command-line option
 
771
to see the specific location on your machine.
444
772
 
445
 
.. _HTML 4.01: http://www.w3.org/TR/html4/
446
773
.. _XHTML 1.0: http://www.w3.org/TR/xhtml1/
447
774
 
448
775
 
451
778
 
452
779
No specific browser is targeted; all modern graphical browsers should
453
780
work.  Some older browsers, text-only browsers, and browsers without
454
 
full CSS support are known to produce inferior results.  Mozilla
455
 
(version 1.0 and up) and MS Internet Explorer (version 5.0 and up) are
456
 
known to give good results.  Reports of experiences with other
457
 
browsers are welcome.
458
 
 
459
 
 
460
 
Unexpected results from tools/html.py: H1, H1 instead of H1, H2.  Why?
461
 
----------------------------------------------------------------------
 
781
full CSS support are known to produce inferior results.  Firefox,
 
782
Safari, Mozilla (version 1.0 and up), and MS Internet Explorer
 
783
(version 5.0 and up) are known to give good results.  Reports of
 
784
experiences with other browsers are welcome.
 
785
 
 
786
 
 
787
Unexpected results from tools/rst2html.py: H1, H1 instead of H1, H2.  Why?
 
788
--------------------------------------------------------------------------
462
789
 
463
790
Here's the question in full:
464
791
 
480
807
 
481
808
        Yeah, imagine me, I'm stuck at H3!  No?!?
482
809
 
483
 
    When I run it through tools/html.py, I get unexpected results
 
810
    When I run it through tools/rst2html.py, I get unexpected results
484
811
    (below).  I was expecting H1, H2, then H3; instead, I get H1, H1,
485
812
    H2::
486
813
 
489
816
        <head>
490
817
        ...
491
818
        <title>Heading 1</title>
492
 
        <link rel="stylesheet" href="default.css" type="text/css" />
493
819
        </head>
494
820
        <body>
495
821
        <div class="document" id="heading-1">
512
838
subtitle.
513
839
 
514
840
If there's only one highest-level section title at the beginning of a
515
 
document, it is treated specially, as the document title.  (Similarly,
516
 
a lone second-highest-level section title may become the document
517
 
subtitle.)  Rather than use a plain H1 for that, we use ``<h1
 
841
document, it is treated specially, as the document title.  (Similarly, a
 
842
lone second-highest-level section title may become the document
 
843
subtitle.)  See `How can I indicate the document title?  Subtitle?`_ for
 
844
details.  Rather than use a plain H1 for the document title, we use ``<h1
518
845
class="title">`` so that we can use H1 again within the document.  Why
519
 
do we do this?  HTML only has H1-H6, so by making H1 do double duty,
520
 
we effectively reserve these tags to provide 6 levels of heading
521
 
beyond the single document title.
 
846
do we do this?  HTML only has H1-H6, so by making H1 do double duty, we
 
847
effectively reserve these tags to provide 6 levels of heading beyond the
 
848
single document title.
522
849
 
523
850
HTML is being used for dumb formatting for nothing but final display.
524
 
A stylesheet *is required*, and one is provided:
525
 
tools/stylesheets/default.css.  Of course, you're welcome to roll your
 
851
A stylesheet *is required*, and one is provided; see `What kind of
 
852
HTML does it produce?`_ above.  Of course, you're welcome to roll your
526
853
own.  The default stylesheet provides rules to format ``<h1
527
854
class="title">`` and ``<h2 class="subtitle">`` differently from
528
855
ordinary ``<h1>`` and ``<h2>``::
533
860
    h2.subtitle {
534
861
      text-align: center }
535
862
 
 
863
If you don't want the top section heading to be interpreted as a
 
864
title at all, disable the `doctitle_xform`_ setting
 
865
(``--no-doc-title`` option).  This will interpret your document
 
866
differently from the standard settings, which might not be a good
 
867
idea.  If you don't like the reuse of the H1 in the HTML output, you
 
868
can tweak the `initial_header_level`_ setting
 
869
(``--initial-header-level`` option) -- but unless you match its value
 
870
to your specific document, you might end up with bad HTML (e.g. H3
 
871
without H2).
 
872
 
 
873
.. _doctitle_xform:
 
874
   http://docutils.sourceforge.net/docs/user/config.html#doctitle-xform
 
875
.. _initial_header_level:
 
876
   http://docutils.sourceforge.net/docs/user/config.html#initial-header-level
 
877
 
536
878
(Thanks to Mark McEahern for the question and much of the answer.)
537
879
 
538
880
 
542
884
The rendering of enumerators (the numbers or letters acting as list
543
885
markers) is completely governed by the stylesheet, so either the
544
886
browser can't find the stylesheet (try using the "--embed-stylesheet"
545
 
option), or the browser can't understand it (try a recent Mozilla or
546
 
MSIE).
 
887
option), or the browser can't understand it (try a recent Firefox,
 
888
Mozilla, Konqueror, Opera, Safari, or even MSIE).
 
889
 
 
890
 
 
891
There appear to be garbage characters in the HTML.  What's up?
 
892
--------------------------------------------------------------
 
893
 
 
894
What you're seeing is most probably not garbage, but the result of a
 
895
mismatch between the actual encoding of the HTML output and the
 
896
encoding your browser is expecting.  Your browser is misinterpreting
 
897
the HTML data, which is encoded text.  A discussion of text encodings
 
898
is beyond the scope of this FAQ; see one or more of these documents
 
899
for more info:
 
900
 
 
901
* `UTF-8 and Unicode FAQ for Unix/Linux
 
902
  <http://www.cl.cam.ac.uk/~mgk25/unicode.html>`_
 
903
 
 
904
* Chapters 3 and 4 of `Introduction to i18n [Internationalization]
 
905
  <http://www.debian.org/doc/manuals/intro-i18n/>`_
 
906
 
 
907
* `Python Unicode Tutorial
 
908
  <http://www.reportlab.com/i18n/python_unicode_tutorial.html>`_
 
909
 
 
910
* `Python Unicode Objects: Some Observations on Working With Non-ASCII
 
911
  Character Sets <http://effbot.org/zone/unicode-objects.htm>`_
 
912
 
 
913
The common case is with the default output encoding (UTF-8), when
 
914
either numbered sections are used (via the "sectnum_" directive) or
 
915
symbol-footnotes.  3 non-breaking spaces are inserted in each numbered
 
916
section title, between the generated number and the title text.  Most
 
917
footnote symbols are not available in ASCII, nor are non-breaking
 
918
spaces.  When encoded with UTF-8 and viewed with ordinary ASCII tools,
 
919
these characters will appear to be multi-character garbage.
 
920
 
 
921
You may have an decoding problem in your browser (or editor, etc.).
 
922
The encoding of the output is set to "utf-8", but your browswer isn't
 
923
recognizing that.  You can either try to fix your browser (enable
 
924
"UTF-8 character set", sometimes called "Unicode"), or choose a
 
925
different encoding for the HTML output.  You can also try
 
926
``--output-encoding=ascii:xmlcharrefreplace`` for HTML (not applicable
 
927
to non-XMLish outputs).
 
928
 
 
929
If you're generating document fragments, the "Content-Type" metadata
 
930
(between the HTML ``<head>`` and ``</head>`` tags) must agree with the
 
931
encoding of the rest of the document.  For UTF-8, it should be::
 
932
 
 
933
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
934
 
 
935
Also, Docutils normally generates an XML declaration as the first line
 
936
of the output.  It must also match the document encoding.  For UTF-8::
 
937
 
 
938
    <?xml version="1.0" encoding="utf-8" ?>
 
939
 
 
940
.. _sectnum:
 
941
   http://docutils.sourceforge.net/docs/ref/rst/directives.html#sectnum
 
942
 
 
943
 
 
944
How can I retrieve the body of the HTML document?
 
945
-------------------------------------------------
 
946
 
 
947
(This is usually needed when using Docutils in conjunction with a
 
948
templating system.)
 
949
 
 
950
You can use the `docutils.core.publish_parts()`_ function, which
 
951
returns a dictionary containing an 'html_body_' entry.
 
952
 
 
953
.. _docutils.core.publish_parts():
 
954
   docs/api/publisher.html#publish-parts
 
955
.. _html_body:
 
956
   docs/api/publisher.html#html-body
 
957
 
 
958
 
 
959
Why is the Docutils XHTML served as "Content-type: text/html"?
 
960
--------------------------------------------------------------
 
961
 
 
962
Full question:
 
963
 
 
964
    Docutils' HTML output looks like XHTML and is advertised as such::
 
965
 
 
966
      <?xml version="1.0" encoding="utf-8" ?>
 
967
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
968
       "http://www.w3.org/TR/xht ml1/DTD/xhtml1-transitional.dtd">
 
969
 
 
970
    But this is followed by::
 
971
 
 
972
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
973
 
 
974
    Shouldn't this be "application/xhtml+xml" instead of "text/html"?
 
975
 
 
976
In a perfect web, the Docutils XHTML output would be 100% strict
 
977
XHTML.  But it's not a perfect web, and a major source of imperfection
 
978
is Internet Explorer.  Despite it's drawbacks, IE still represents the
 
979
majority of web browsers, and cannot be ignored.
 
980
 
 
981
Short answer: if we didn't serve XHTML as "text/html" (which is a
 
982
perfectly valid thing to do), it couldn't be viewed in Internet
 
983
Explorer.  
 
984
 
 
985
Long answer: see the `"Criticisms of Internet Explorer" Wikipedia
 
986
entry <http://en.wikipedia.org/wiki/Criticisms_of_Internet_Explorer#XHTML>`__.
 
987
 
 
988
However, there's also `Sending XHTML as text/html Considered
 
989
Harmful`__.  What to do, what to do?  We're damned no matter what we
 
990
do.  So we'll continue to do the practical instead of the pure:
 
991
support the browsers that are actually out there, and not fight for
 
992
strict standards compliance.
 
993
 
 
994
__ http://hixie.ch/advocacy/xhtml
 
995
 
 
996
(Thanks to Martin F. Krafft, Robert Kern, Michael Foord, and Alan
 
997
G. Isaac.)
547
998
 
548
999
 
549
1000
Python Source Reader