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

« back to all changes in this revision

Viewing changes to docs/api/publisher.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
 The Docutils Publisher
 
3
========================
 
4
 
 
5
:Author: David Goodger
 
6
:Contact: goodger@python.org
 
7
:Date: $Date: 2005-06-27 13:25:47 +0200 (Mon, 27 Jun 2005) $
 
8
:Revision: $Revision: 3599 $
 
9
:Copyright: This document has been placed in the public domain.
 
10
 
 
11
.. contents::
 
12
 
 
13
 
 
14
Publisher Convenience Functions
 
15
===============================
 
16
 
 
17
Each of these functions set up a ``docutils.core.Publisher`` object,
 
18
then call its ``publish`` method.  ``docutils.core.Publisher.publish``
 
19
handles everything else.  There are five convenience functions in the
 
20
``docutils.core`` module:
 
21
 
 
22
:_`publish_cmdline`: for command-line front-end tools, like
 
23
  ``rst2html.py``.  There are several examples in the ``tools/``
 
24
  directory.  A detailed analysis of one such tool is in `Inside A
 
25
  Docutils Command-Line Front-End Tool`_
 
26
 
 
27
:_`publish_file`: for programmatic use with file-like I/O.  In
 
28
  addition to writing the encoded output to a file, also returns the
 
29
  encoded output as a string.
 
30
 
 
31
:_`publish_string`: for programmatic use with string I/O.  Returns
 
32
  the encoded output as a string.
 
33
 
 
34
:_`publish_parts`: for programmatic use with string input; returns a
 
35
  dictionary of document parts.  Dictionary keys are the names of
 
36
  parts, and values are Unicode strings; encoding is up to the client.
 
37
  Useful when only portions of the processed document are desired.
 
38
  See `publish_parts Details`_ below.
 
39
 
 
40
  There are usage examples in the `docutils/examples.py`_ module.
 
41
 
 
42
:_`publish_programmatically`: for custom programmatic use.  This
 
43
  function implements common code and is used by ``publish_file``,
 
44
  ``publish_string``, and ``publish_parts``.  It returns a 2-tuple:
 
45
  the encoded string output and the Publisher object.
 
46
 
 
47
.. _Inside A Docutils Command-Line Front-End Tool: ./cmdline-tool.html
 
48
.. _docutils/examples.py: ../../docutils/examples.py
 
49
 
 
50
 
 
51
Configuration
 
52
-------------
 
53
 
 
54
To pass application-specific setting defaults to the Publisher
 
55
convenience functions, use the ``settings_overrides`` parameter.  Pass
 
56
a dictionary of setting names & values, like this::
 
57
 
 
58
    overrides = {'input_encoding': 'ascii',
 
59
                 'output_encoding': 'latin-1'}
 
60
    output = publish_string(..., settings_overrides=overrides)
 
61
 
 
62
Settings from command-line options override configuration file
 
63
settings, and they override application defaults.  For details, see
 
64
`Docutils Runtime Settings`_.  See `Docutils Configuration Files`_ for
 
65
details about individual settings.
 
66
 
 
67
.. _Docutils Runtime Settings: ./runtime-settings.html
 
68
.. _Docutils Configuration Files: ../user/tools.html
 
69
 
 
70
 
 
71
Encodings
 
72
---------
 
73
 
 
74
The default output encoding of Docutils is UTF-8.  If you have any
 
75
non-ASCII in your input text, you may have to do a bit more setup.
 
76
Docutils may introduce some non-ASCII text if you use
 
77
`auto-symbol footnotes`_ or the `"contents" directive`_.
 
78
 
 
79
.. _auto-symbol footnotes:
 
80
   ../ref/rst/restructuredtext.html#auto-symbol-footnotes
 
81
.. _"contents" directive:
 
82
   ../ref/rst/directives.html#table-of-contents
 
83
 
 
84
 
 
85
``publish_parts`` Details
 
86
=========================
 
87
 
 
88
The ``docutils.core.publish_parts`` convenience function returns a
 
89
dictionary of document parts.  Dictionary keys are the names of parts,
 
90
and values are Unicode strings.
 
91
 
 
92
Each Writer component may publish a different set of document parts,
 
93
described below.  Currently only the HTML Writer implements more than
 
94
the "whole" part.
 
95
 
 
96
 
 
97
Parts Provided By All Writers
 
98
-----------------------------
 
99
 
 
100
_`whole`
 
101
    ``parts['whole']`` contains the entire formatted document.
 
102
 
 
103
 
 
104
Parts Provided By the HTML Writer
 
105
---------------------------------
 
106
 
 
107
_`body`
 
108
    ``parts['body']`` is equivalent to parts['fragment_'].  It is
 
109
    *not* equivalent to parts['html_body_'].
 
110
 
 
111
_`docinfo`
 
112
    ``parts['docinfo']`` contains the document bibliographic data.
 
113
 
 
114
_`footer`
 
115
    ``parts['footer']`` contains the document footer content, meant to
 
116
    appear at the bottom of a web page, or repeated at the bottom of
 
117
    every printed page.
 
118
 
 
119
_`fragment`
 
120
    ``parts['fragment']`` contains the document body (*not* the HTML
 
121
    ``<body>``).  In other words, it contains the entire document,
 
122
    less the document title, subtitle, docinfo, header, and footer.
 
123
 
 
124
_`header`
 
125
    ``parts['header']`` contains the document header content, meant to
 
126
    appear at the top of a web page, or repeated at the top of every
 
127
    printed page.
 
128
 
 
129
_`html_body`
 
130
    ``parts['html_body']`` contains the HTML ``<body>`` content, less
 
131
    the ``<body>`` and ``</body>`` tags themselves.
 
132
 
 
133
_`html_head`
 
134
    ``parts['html_head']`` contains the HTML ``<head>`` content, less
 
135
    the stylesheet link and the ``<head>`` and ``</head>`` tags
 
136
    themselves.  Since ``publish_parts`` returns Unicode strings and
 
137
    does not know about the output encoding, the "Content-Type" meta
 
138
    tag's "charset" value is left unresolved, as "%s"::
 
139
 
 
140
        <meta http-equiv="Content-Type" content="text/html; charset=%s" />
 
141
 
 
142
    The interpolation should be done by client code.
 
143
 
 
144
_`html_prolog`
 
145
    ``parts['html_prolog]`` contains the XML declaration and the
 
146
    doctype declaration.  The XML declaration's "encoding" attribute's
 
147
    value is left unresolved, as "%s"::
 
148
 
 
149
        <?xml version="1.0" encoding="%s" ?>
 
150
 
 
151
    The interpolation should be done by client code.
 
152
 
 
153
_`html_subtitle`
 
154
    ``parts['html_subtitle']`` contains the document subtitle,
 
155
    including the enclosing ``<h2 class="subtitle">`` & ``</h2>``
 
156
    tags.
 
157
 
 
158
_`html_title`
 
159
    ``parts['html_title']`` contains the document title, including the
 
160
    enclosing ``<h1 class="title">`` & ``</h1>`` tags.
 
161
 
 
162
_`meta`
 
163
    ``parts['meta']`` contains all ``<meta ... />`` tags.
 
164
 
 
165
_`stylesheet`
 
166
    ``parts['stylesheet']`` contains the document stylesheet link.
 
167
 
 
168
_`subtitle`
 
169
    ``parts['subtitle']`` contains the document subtitle text and any
 
170
    inline markup.  It does not include the enclosing ``<h2>`` &
 
171
    ``</h2>`` tags.
 
172
 
 
173
_`title`
 
174
    ``parts['title']`` contains the document title text and any inline
 
175
    markup.  It does not include the enclosing ``<h1>`` & ``</h1>``
 
176
    tags.