~ubuntu-branches/ubuntu/hardy/python-docutils/hardy

« back to all changes in this revision

Viewing changes to docs/ref/rst/roles.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
 reStructuredText Interpreted Text Roles
 
3
=========================================
 
4
 
 
5
:Author: David Goodger
 
6
:Contact: goodger@users.sourceforge.net
 
7
:Revision: $Revision: 3978 $
 
8
:Date: $Date: 2005-10-29 23:17:26 +0200 (Sat, 29 Oct 2005) $
 
9
:Copyright: This document has been placed in the public domain.
 
10
 
 
11
This document describes the interpreted text roles implemented in the
 
12
reference reStructuredText parser.
 
13
 
 
14
Interpreted text uses backquotes (`) around the text.  An explicit
 
15
role marker may optionally appear before or after the text, delimited
 
16
with colons.  For example::
 
17
 
 
18
    This is `interpreted text` using the default role.
 
19
 
 
20
    This is :title:`interpreted text` using an explicit role.
 
21
 
 
22
A default role may be defined by applications of reStructuredText; it
 
23
is used if no explicit ``:role:`` prefix or suffix is given.  The
 
24
"default default role" is `:title-reference:`_.  It can be changed
 
25
using the default-role_ directive.
 
26
 
 
27
See the `Interpreted Text`_ section in the `reStructuredText Markup
 
28
Specification`_ for syntax details.  For details on the hierarchy of
 
29
elements, please see `The Docutils Document Tree`_ and the `Docutils
 
30
Generic DTD`_ XML document type definition.  For interpreted text role
 
31
implementation details, see `Creating reStructuredText Interpreted
 
32
Text Roles`_.
 
33
 
 
34
.. _"role" directive: directives.html#role
 
35
.. _default-role: directives.html#default-role
 
36
.. _Interpreted Text: restructuredtext.html#interpreted-text
 
37
.. _reStructuredText Markup Specification: restructuredtext.html
 
38
.. _The Docutils Document Tree: ../doctree.html
 
39
.. _Docutils Generic DTD: ../docutils.dtd
 
40
.. _Creating reStructuredText Interpreted Text Roles:
 
41
   ../../howto/rst-roles.html
 
42
 
 
43
 
 
44
.. contents::
 
45
 
 
46
 
 
47
---------------
 
48
 Customization
 
49
---------------
 
50
 
 
51
Custom interpreted text roles may be defined in a document with the
 
52
`"role" directive`_.  Customization details are listed with each role.
 
53
 
 
54
.. _class:
 
55
 
 
56
A ``class`` option is recognized by the "role" directive for most
 
57
interpreted text roles.  A description__ is provided in the `"role"
 
58
directive`_ documentation.
 
59
 
 
60
__ directives.html#role-class
 
61
 
 
62
 
 
63
----------------
 
64
 Standard Roles
 
65
----------------
 
66
 
 
67
``:emphasis:``
 
68
==============
 
69
 
 
70
:Aliases: None
 
71
:DTD Element: emphasis
 
72
:Customization:
 
73
    :Options: class_.
 
74
    :Content: None.
 
75
 
 
76
Implements emphasis.  These are equivalent::
 
77
 
 
78
    *text*
 
79
    :emphasis:`text`
 
80
 
 
81
 
 
82
``:literal:``
 
83
==============
 
84
 
 
85
:Aliases: None
 
86
:DTD Element: literal
 
87
:Customization:
 
88
    :Options: class_.
 
89
    :Content: None.
 
90
 
 
91
Implements inline literal text.  These are equivalent::
 
92
 
 
93
    ``text``
 
94
    :literal:`text`
 
95
 
 
96
Care must be taken with backslash-escapes though.  These are *not*
 
97
equivalent::
 
98
 
 
99
    ``text \ and \ backslashes``
 
100
    :literal:`text \ and \ backslashes`
 
101
 
 
102
The backslashes in the first line are preserved (and do nothing),
 
103
whereas the backslashes in the second line escape the following
 
104
spaces.
 
105
 
 
106
 
 
107
``:pep-reference:``
 
108
===================
 
109
 
 
110
:Aliases: ``:PEP:``
 
111
:DTD Element: reference
 
112
:Customization:
 
113
    :Options: class_.
 
114
    :Content: None.
 
115
 
 
116
The ``:pep-reference:`` role is used to create an HTTP reference to a
 
117
PEP (Python Enhancement Proposal).  The ``:PEP:`` alias is usually
 
118
used.  For example::
 
119
 
 
120
    See :PEP:`287` for more information about reStructuredText.
 
121
 
 
122
This is equivalent to::
 
123
 
 
124
    See `PEP 287`__ for more information about reStructuredText.
 
125
 
 
126
    __ http://www.python.org/peps/pep-0287.html
 
127
 
 
128
 
 
129
``:rfc-reference:``
 
130
===================
 
131
 
 
132
:Aliases: ``:RFC:``
 
133
:DTD Element: reference
 
134
:Customization:
 
135
    :Options: class_.
 
136
    :Content: None.
 
137
 
 
138
The ``:rfc-reference:`` role is used to create an HTTP reference to an
 
139
RFC (Internet Request for Comments).  The ``:RFC:`` alias is usually
 
140
used.  For example::
 
141
 
 
142
    See :RFC:`2822` for information about email headers.
 
143
 
 
144
This is equivalent to::
 
145
 
 
146
    See `RFC 2822`__ for information about email headers.
 
147
 
 
148
    __ http://www.faqs.org/rfcs/rfc2822.html
 
149
 
 
150
 
 
151
``:strong:``
 
152
============
 
153
 
 
154
:Aliases: None
 
155
:DTD Element: strong
 
156
:Customization:
 
157
    :Options: class_.
 
158
    :Content: None.
 
159
 
 
160
Implements strong emphasis.  These are equivalent::
 
161
 
 
162
    **text**
 
163
    :strong:`text`
 
164
 
 
165
 
 
166
``:subscript:``
 
167
===============
 
168
 
 
169
:Aliases: ``:sub:``
 
170
:DTD Element: subscript
 
171
:Customization:
 
172
    :Options: class_.
 
173
    :Content: None.
 
174
 
 
175
Implements subscripts.
 
176
 
 
177
.. Tip::
 
178
 
 
179
   Whitespace or punctuation is required around interpreted text, but
 
180
   often not desired with subscripts & superscripts.
 
181
   Backslash-escaped whitespace can be used; the whitespace will be
 
182
   removed from the processed document::
 
183
 
 
184
       H\ :sub:`2`\ O
 
185
       E = mc\ :sup:`2`
 
186
 
 
187
   In such cases, readability of the plain text can be greatly
 
188
   improved with substitutions::
 
189
 
 
190
       The chemical formula for pure water is |H2O|.
 
191
 
 
192
       .. |H2O| replace:: H\ :sub:`2`\ O
 
193
 
 
194
   See `the reStructuredText spec`__ for further information on
 
195
   `character-level markup`__ and `the substitution mechanism`__.
 
196
 
 
197
   __ restructuredtext.html
 
198
   __ restructuredtext.html#character-level-inline-markup
 
199
   __ restructuredtext.html#substitution-references
 
200
 
 
201
 
 
202
``:superscript:``
 
203
=================
 
204
 
 
205
:Aliases: ``:sup:``
 
206
:DTD Element: superscript
 
207
:Customization:
 
208
    :Options: class_.
 
209
    :Content: None.
 
210
 
 
211
Implements superscripts.  See the tip in `:subscript:`_ above.
 
212
 
 
213
 
 
214
``:title-reference:``
 
215
=====================
 
216
 
 
217
:Aliases: ``:title:``, ``:t:``.
 
218
:DTD Element: title_reference
 
219
:Customization:
 
220
    :Options: class_.
 
221
    :Content: None.
 
222
 
 
223
The ``:title-reference:`` role is used to describe the titles of
 
224
books, periodicals, and other materials.  It is the equivalent of the
 
225
HTML "cite" element, and it is expected that HTML writers will
 
226
typically render "title_reference" elements using "cite".
 
227
 
 
228
Since title references are typically rendered with italics, they are
 
229
often marked up using ``*emphasis*``, which is misleading and vague. 
 
230
The "title_reference" element provides accurate and unambiguous
 
231
descriptive markup.
 
232
 
 
233
Let's assume ``:title-reference:`` is the default interpreted text
 
234
role (see below) for this example::
 
235
 
 
236
    `Design Patterns` [GoF95]_ is an excellent read.
 
237
 
 
238
The following document fragment (pseudo-XML_) will result from
 
239
processing::
 
240
 
 
241
    <paragraph>
 
242
        <title_reference>
 
243
            Design Patterns
 
244
 
 
245
        <citation_reference refname="gof95">
 
246
            GoF95
 
247
         is an excellent read.
 
248
 
 
249
``:title-reference:`` is the default interpreted text role in the
 
250
standard reStructuredText parser.  This means that no explicit role is
 
251
required.  Applications of reStructuredText may designate a different
 
252
default role, in which case the explicit ``:title-reference:`` role
 
253
must be used to obtain a ``title_reference`` element.
 
254
 
 
255
 
 
256
.. _pseudo-XML: ../doctree.html#pseudo-xml
 
257
 
 
258
 
 
259
-------------------
 
260
 Specialized Roles
 
261
-------------------
 
262
 
 
263
``raw``
 
264
=======
 
265
 
 
266
:Aliases: None
 
267
:DTD Element: raw
 
268
:Customization:
 
269
    :Options: class_, format
 
270
    :Content: None
 
271
 
 
272
.. WARNING::
 
273
 
 
274
   The "raw" role is a stop-gap measure allowing the author to bypass
 
275
   reStructuredText's markup.  It is a "power-user" feature that
 
276
   should not be overused or abused.  The use of "raw" ties documents
 
277
   to specific output formats and makes them less portable.
 
278
 
 
279
   If you often need to use "raw"-derived interpreted text roles or
 
280
   the "raw" directive, that is a sign either of overuse/abuse or that
 
281
   functionality may be missing from reStructuredText.  Please
 
282
   describe your situation in a message to the Docutils-users_ mailing
 
283
   list.
 
284
 
 
285
   .. _Docutils-users: ../../user/mailing-lists.html#docutils-user
 
286
 
 
287
The "raw" role indicates non-reStructuredText data that is to be
 
288
passed untouched to the Writer.  It is the inline equivalent of the
 
289
`"raw" directive`_; see its documentation for details on the
 
290
semantics.
 
291
 
 
292
.. _"raw" directive: directives.html#raw
 
293
 
 
294
The "raw" role cannot be used directly.  The `"role" directive`_ must
 
295
first be used to build custom roles based on the "raw" role.  One or
 
296
more formats (Writer names) must be provided in a "format" option.
 
297
 
 
298
For example, the following creates an HTML-specific "raw-html" role::
 
299
 
 
300
    .. role:: raw-html(raw)
 
301
       :format: html
 
302
 
 
303
This role can now be used directly to pass data untouched to the HTML
 
304
Writer.  For example::
 
305
 
 
306
    If there just *has* to be a line break here,
 
307
    :raw-html:`<br />`
 
308
    it can be accomplished with a "raw"-derived role.
 
309
    But the line block syntax should be considered first.
 
310
 
 
311
.. Tip:: Roles based on "raw" should clearly indicate their origin, so
 
312
   they are not mistaken for reStructuredText markup.  Using a "raw-"
 
313
   prefix for role names is recommended.
 
314
 
 
315
In addition to "class_", the following option is recognized:
 
316
 
 
317
``format`` : text
 
318
    One or more space-separated output format names (Writer names).