Debian Codegraph @

docs/user/tools.rst

raw ◀ ▶
1 Debian patch touch this file
1 .. include:: ../header.rst
2
3 ==========================
4 Docutils Front-End Tools
5 ==========================
6
7 :Author: David Goodger
8 :Contact: [email protected]
9 :Revision: $Revision: 9993 $
10 :Date: $Date: 2024-12-04 14:32:20 +0100 (Mi, 04. Dez 2024) $
11 :Copyright: This document has been placed in the public domain.
12
13 .. contents::
14
15 --------------
16 Introduction
17 --------------
18
19 In addition to the generic "docutils_" application, Docutils installs
20 a set of small front ends, each specialized for a specific
21 "Reader" (which knows how to interpret a file in context),
22 "Parser" (which understands the syntax of the text), and
23 "Writer" (which knows how to generate a specific data format).
24
25 .. note::
26 Docutils front-end tool names, install details and the set of
27 auto-installed tools changed in Docutils 0.21 (see the RELEASE-NOTES_).
28
29 .. _usage pattern:
30
31 Most [#]_ front-end tools have common options and the same command-line
32 usage pattern::
33
34 <toolname> [options] [<source> [<destination>]]
35
36 See `the tools`_ below for concrete examples.
37
38 Each tool has a "``--help``" option which lists the
39 `command-line options`_ and arguments it supports.
40 Processing can also be customized with `configuration files`_.
41
42 The two arguments, "source" and "destination", are optional. If only
43 one argument (source) is specified, the standard output (stdout) is
44 used for the destination. If no arguments are specified, the standard
45 input (stdin) is used for the source.
46
47 .. [#] The exception is buildhtml.py_.
48
49 .. note::
50 The command line usage pattern will change over the next releases.
51
52 See `Future changes`_ in the RELEASE-NOTES.
53
54
55 .. _RELEASE-NOTES: ../../RELEASE-NOTES.html
56 .. _future changes: ../../RELEASE-NOTES.html#future-changes
57
58
59 Getting Help
60 ============
61
62 First, try the "``--help``" option each front-end tool has.
63
64 Command line options and their corresponding configuration file entries
65 are detailed in `Docutils Configuration`_.
66
67 Users who have questions or need assistance with Docutils or
68 reStructuredText should post a message to the Docutils-users_ mailing
69 list.
70
71 .. _Docutils-users: mailing-lists.html#docutils-users
72
73
74 -----------
75 The Tools
76 -----------
77
78 Generic Command Line Front End
79 ==============================
80
81 docutils
82 --------
83
84 :CLI name: ``docutils``
85 :Readers: Standalone (default), PEP
86 :Parsers: reStructuredText (default), Markdown (requires 3rd party packages)
87 :Writers: html_, html4css1_, html5_ (default), latex2e_, manpage_,
88 odt_, pep_html_, pseudo-xml_, s5_html_, xelatex_, xml_,
89 :Config_: `[docutils application]`_
90
91 Since Docutils 0.19, you can start the generic front end like::
92
93 docutils test.rst > test.html
94
95 Alternatively, use Python's ``-m`` option, or the ``docutils-cli.py``
96 script in the ``tools/`` directory.
97
98 The generic front end allows combining "reader", "parser", and
99 "writer" components from the Docutils package or 3rd party plug-ins.
100
101 For example, to process a Markdown_ file "``test.md``" into
102 Pseudo-XML_::
103
104 docutils --parser=markdown --writer=pseudoxml test.md > test.rst
105
106 Another example is converting a reStructuredText PEP_ source into a HTML preview [#]_::
107
108 docutils --reader=pep --writer=pep_html pep-0287.rst > pep-0287.html
109
110 The pep_html_ writer makes use of a "``pep-html-template``" file and
111 the "``pep.css``" stylesheet (both in the ``docutils/writers/pep_html/``
112 directory), but these can be overridden by command-line options or
113 configuration files.
114
115 Use the "--help" option together with the component-selection options
116 to get the correct list of supported command-line options. Example::
117
118 docutils --parser=markdown --writer=xml --help
119
120 .. [#] The rendering of published PEPs is done by a Sphinx-based build system
121 (see :PEP:`676`).
122
123 .. _[docutils application]: config.html#docutils-application
124 .. _Markdown: https://www.markdownguide.org/
125 .. _PEP: https://peps.python.org
126 .. _pep_html: html.html#pep-html
127
128
129 HTML-Generating Tools
130 =====================
131
132 .. _rst2html.py:
133
134 rst2html
135 --------
136
137 :Reader: Standalone
138 :Parser: reStructuredText
139 :Writer: html_
140
141 ``rst2html`` is the front-end for the default Docutils HTML writer.
142 The default writer may change with the development of HTML, browsers,
143 Docutils, and the web.
144 The current default is html4css1_, it will change to html5_ in Docutils 2.0.
145
146 .. caution::
147 Use a specific front end like rst2html4_ or rst2html5_,
148 if you depend on stability of the generated HTML code
149 (e.g., because you use a custom style sheet or post-processing
150 that may break otherwise).
151
152 .. _html: html.html#html
153
154
155 .. _rst2html4.py:
156
157 rst2html4
158 ---------
159
160 :Reader: Standalone
161 :Parser: reStructuredText
162 :Writer: html4css1_
163
164 The ``rst2html4`` front end reads standalone reStructuredText source
165 files and produces `XHTML 1.0 Transitional`_ output.
166 A CSS stylesheet is required for proper rendering; a simple but
167 complete stylesheet is installed and used by default (see Stylesheets_
168 below).
169
170 For example, to process a reStructuredText file "``test.rst``" into
171 HTML::
172
173 rst2html test.rst > test.html
174
175 Now open the "``test.html``" file in your favourite browser to see the
176 results. To get a footer with a link to the source file, date & time
177 of processing, and links to the Docutils project, add some options::
178
179 rst2html --source-link --time --generator test.rst > test.html
180
181
182 Stylesheets
183 ```````````
184
185 ``rst2html`` inserts into the generated HTML a cascading stylesheet
186 (or a link to a stylesheet, when passing the "``--link-stylesheet``"
187 option). A stylesheet is required for proper rendering.
188 The default stylesheet (``docutils/writers/html4css1/html4css1.css``,
189 located in the installation directory) is provided for basic use.
190
191 To use different stylesheet(s), specify the stylesheets' location(s) as
192 comma-separated list with the "`-\-stylesheet`_"
193 or "`-\-stylesheet-path`_" options.
194 To experiment with styles, please see the
195 `guide to writing HTML (CSS) stylesheets for Docutils`__.
196
197 .. _XHTML 1.0 Transitional: https://www.w3.org/TR/xhtml1/
198 .. _html4css1: html.html#html4css1
199 .. _link-stylesheet: config.html#embed-stylesheet
200 .. _--stylesheet: config.html#stylesheet
201 .. _--stylesheet-path: config.html#stylesheet-path
202 __ ../howto/html-stylesheets.html
203
204
205 .. _rst2html5.py:
206
207 rst2html5
208 ---------
209
210 :Reader: Standalone
211 :Parser: reStructuredText
212 :Writer: html5_
213
214 The ``rst2html5`` front end reads standalone reStructuredText source
215 files and produces `HTML 5`_ output.
216 Correct rendering of elements not directly supported by HTML depends on a
217 CSS style sheet. The provided style sheets ``minimal.css`` and ``plain.css``
218 define required and optional styling rules respectively.
219
220 .. _html5: html.html#html5
221 .. _HTML 5: https://www.w3.org/TR/html5/
222
223
224 .. _rst2s5.py:
225
226 rst2s5
227 ------
228
229 :Reader: Standalone
230 :Parser: reStructuredText
231 :Writer: s5_html_
232
233 The ``rst2s5`` front end reads standalone reStructuredText source
234 files and produces (X)HTML output compatible with S5_, the "Simple
235 Standards-based Slide Show System" by Eric Meyer. A theme is required
236 for proper rendering; several are distributed with Docutils and others
237 are available; see Themes_ below.
238
239 For example, to process a reStructuredText file "``slides.rst``" into
240 S5/HTML::
241
242 rst2s5 slides.rst --output=slides.html
243
244 Now open the "``slides.html``" file in your favourite browser, switch
245 to full-screen mode, and enjoy the results.
246
247 .. _S5: http://meyerweb.com/eric/tools/s5/
248 .. _s5_html: html.html#s5-html
249
250 Themes
251 ``````
252
253 Each S5 theme consists of a directory containing several files:
254 stylesheets, JavaScript, and graphics. These are copied into a
255 ``ui/<theme>`` directory beside the generated HTML. [#copy-theme]_
256 A theme is chosen
257 using the "``--theme``" option (for themes that come with Docutils) or
258 the "``--theme-url``" option (for themes anywhere). For example, the
259 "medium-black" theme can be specified as follows::
260
261 rst2s5 --theme medium-black slides.rst --output=slides.html
262
263 The theme will be copied [#copy-theme]_ to the ``ui/medium-black`` directory.
264
265 Several themes are included with Docutils:
266
267 ``default``
268 This is a simplified version of S5's default theme.
269
270 :Main content: black serif text on a white background
271 :Text capacity: about 13 lines
272 :Headers: light blue, bold sans-serif text on a dark blue
273 background; titles are limited to one line
274 :Footers: small, gray, bold sans-serif text on a dark blue
275 background
276
277 ``small-white``
278 (Small text on a white background.)
279
280 :Main content: black serif text on a white background
281 :Text capacity: about 15 lines
282 :Headers: black, bold sans-serif text on a white background;
283 titles wrap
284 :Footers: small, dark gray, bold sans-serif text on a white
285 background
286
287 ``small-black``
288 :Main content: white serif text on a black background
289 :Text capacity: about 15 lines
290 :Headers: white, bold sans-serif text on a black background;
291 titles wrap
292 :Footers: small, light gray, bold sans-serif text on a black
293 background
294
295 ``medium-white``
296 :Main content: black serif text on a white background
297 :Text capacity: about 9 lines
298 :Headers: black, bold sans-serif text on a white background;
299 titles wrap
300 :Footers: small, dark gray, bold sans-serif text on a white
301 background
302
303 ``medium-black``
304 :Main content: white serif text on a black background
305 :Text capacity: about 9 lines
306 :Headers: white, bold sans-serif text on a black background;
307 titles wrap
308 :Footers: small, light gray, bold sans-serif text on a black
309 background
310
311 ``big-white``
312 :Main content: black, bold sans-serif text on a white background
313 :Text capacity: about 5 lines
314 :Headers: black, bold sans-serif text on a white background;
315 titles wrap
316 :Footers: not displayed
317
318 ``big-black``
319 :Main content: white, bold sans-serif text on a black background
320 :Text capacity: about 5 lines
321 :Headers: white, bold sans-serif text on a black background;
322 titles wrap
323 :Footers: not displayed
324
325 If a theme directory contains a file named ``__base__``, the name of
326 the theme's base theme will be read from it. Files are accumulated
327 from the named theme, any base themes, and the "default" theme (which
328 is the implicit base of all themes).
329
330 For details, please see `Easy Slide Shows With reStructuredText & S5
331 <slide-shows.html>`_.
332
333 .. [#copy-theme] Theme files can only be copied by Docutils, if the
334 `output path`_ is specified.
335
336 .. _output path: config.html#output-path
337
338
339 buildhtml.py
340 ------------
341
342 :Readers: Standalone, PEP
343 :Parser: reStructuredText
344 :Writers: html_, html5_, pep_html_
345 :Config_: `[buildhtml application]`_
346
•347 In Debian this tool is installed under the name rst-buildhtml.
348
349 The ``buildhtml.py`` script can be found in the ``/tools`` directory of
350 the "docutils" source. It is not included in binary packages. [#]_
351
352 Usage::
353
•354 rst-buildhtml [options] [<directory> ...]
355
356 Use ``buildhtml.py`` to generate ``*.html`` from reStructuredText
357 source files in each <directory> given, and their subdirectories too.
358 The current directory is chosen by default if no directory is specified.
359 Use the ``--local`` option to skip all subdirectories.
360 See `[buildhtml application]`_ in `Docutils Configuration`_
361 for more specific selection options.
362
363 After unpacking the Docutils source package, you can ``cd`` into its root
364 directory (``docutils-X.Y/`` where "X.Y" is the release version, for
365 official releases) and generate HTML pages for all included documentation
366 files with::
367
368 tools/buildhtml.py
369
370 Some files may generate system messages (docs/user/rst/demo.rst contains
371 intentional errors); use the ``--quiet`` option to suppress all warnings.
372
373 .. [#] The Debian package "python3-docutils" includes the script
374 under the name ``rst-buildhtml``.
375
376 .. _[buildhtml application]: config.html#buildhtml-application
377 .. _configuration file: `configuration files`_
378
379
380 LaTeX-Generating Tools
381 ======================
382
383 .. _rst2latex.py:
384
385 rst2latex
386 ---------
387
388 :Reader: Standalone
389 :Parser: reStructuredText
390 :Writer: latex2e_
391
392 The ``rst2latex`` front end reads standalone reStructuredText
393 source files and produces LaTeX_ output. For example, to process a
394 reStructuredText file "``test.rst``" into LaTeX::
395
396 rst2latex test.rst > test.tex
397
398 The output file "``test.tex``" should then be processed with ``latex``
399 or ``pdflatex`` to get a document in DVI, PostScript or PDF format for
400 printing or on-screen viewing.
401
402 For details see `Generating LaTeX with Docutils`_.
403
404 .. _latex2e:
405 .. _Generating LaTeX with Docutils: latex.html
406
407
408 .. _rst2xetex.py:
409
410 rst2xetex
411 ---------
412
413 :Reader: Standalone
414 :Parser: reStructuredText
415 :Writer: _`xelatex`
416
417 The ``rst2xetex`` front end reads standalone reStructuredText source
418 files and produces `LaTeX` output for processing with Unicode-aware
419 TeX engines (`LuaTeX`_ or `XeTeX`_). For example, to process a
420 reStructuredText file "``test.rst``" into LaTeX::
421
422 rst2xetex test.rst > test.tex
423
424 The output file "``test.tex``" should then be processed with ``xelatex`` or
425 ``lualatex`` to get a document in PDF format for printing or on-screen
426 viewing.
427
428 For details see `Generating LaTeX with Docutils`_.
429
430 .. _LaTeX: https://en.wikipedia.org/wiki/LaTeX
431 .. _XeTeX: https://en.wikipedia.org/wiki/XeTeX
432 .. _LuaTeX: https://en.wikipedia.org/wiki/LuaTeX
433
434
435 Man-Page-Generating Tools
436 =========================
437
438 .. _rst2man.py:
439
440 rst2man
441 -------
442
443 :Reader: Standalone
444 :Parser: reStructuredText
445 :Writer: manpage_
446
447 The ``rst2man`` front end reads standalone reStructuredText source
448 files and produces troff_ sources for Unix man pages.
449
450 .. _manpage: manpage.html
451 .. _troff: https://troff.org/
452
453
454 OpenDocument-Generating Tools
455 =============================
456
457 .. _rst2odt.py:
458
459 rst2odt
460 -------
461
462 :Reader: Standalone
463 :Parser: reStructuredText
464 :Writer: odt_
465
466 The ``rst2odt`` front end reads standalone reStructuredText
467 source files and produces ODF/.odt files that can be read, edited,
468 printed, etc with OpenOffice_ ``oowriter`` or LibreOffice_ ``lowriter``.
469 A stylesheet file is required. A
470 stylesheet file is an OpenOffice .odt file containing definitions
471 of the styles required for ``rst2odt``.
472 For details, see `Odt Writer for Docutils`_.
473
474 .. _OpenOffice: https://www.openoffice.org/
475 .. _LibreOffice: https://www.libreoffice.org/
476 .. _odt:
477 .. _Odt Writer for Docutils: odt.html
478
479
480
481 reStructuredText-Generating Tools
482 =================================
483
484 Currently, there is no reStructuredText writer in Docutils and therefore
485 an ``rst2rst`` tool is still missing.
486
487 To generate reStructuredText documents with Docutils, you can use
488 the XML (Docutils native) writer and the xml2rst_ processor.
489
490
491 XML-Generating Tools
492 ====================
493
494 .. _rst2xml.py:
495
496 rst2xml
497 -------
498
499 :Reader: Standalone
500 :Parser: reStructuredText
501 :Writer: _`XML` (Docutils native)
502
503 The ``rst2xml`` front end produces Docutils-native XML output.
504 This can be transformed with standard XML tools such as XSLT
505 processors into arbitrary final forms. An example is the xml2rst_ processor
506 by Stefan Merten.
507
508 .. _xml2rst: http://www.merten-home.de/FreeSoftware/xml2rst/index.html
509
510
511 Testing/Debugging Tools
512 =======================
513
514 .. _rst2pseudoxml.py:
515
516 rst2pseudoxml
517 -------------
518
519 :Reader: Standalone
520 :Parser: reStructuredText
521 :Writer: _`Pseudo-XML`
522
523 ``rst2pseudoxml`` is used for debugging the Docutils "Reader to
524 Transform to Writer" pipeline. It produces a compact pretty-printed
525 "pseudo-XML", where nesting is indicated by indentation (no end-tags).
526 External attributes for all elements are output, and internal
527 attributes for any leftover "pending" elements are also given.
528
529
530 ---------------
531 Customization
532 ---------------
533
534 All front-end tools support the options/settings from the generic
535 `configuration file sections`_ plus the sections of their components
536 (reader, writer, parser).
537 Some front-end tools also add application-specific settings.
538
539
540 Command-Line Options
541 ====================
542
543 Command-line options are intended for one-off customization.
544 They take priority over configuration file settings.
545
546 Use the ``--help`` option on each of the front ends to list the
547 command-line options it supports.
548
549
550 Configuration Files
551 ===================
552
553 Configuration files are used for persistent customization; they can be
554 set once and take effect every time you use a front-end tool.
555
556 Command-line options and their corresponding configuration file entry
557 names are listed in the `Docutils Configuration`_ document.
558
559 .. _Docutils Configuration: config.html
560 .. _Config:
561 .. _configuration file sections:
562 config.html#configuration-file-sections-entries
563
564 .. Emacs settings
565
566 Local Variables:
567 mode: indented-text
568 mode: rst
569 indent-tabs-mode: nil
570 sentence-end-double-space: t
571 fill-column: 70
572 End: