Key: Deleted text. Inserted text. Use < and > to jump to previous/next difference region.
> reStructuredText Interpreted Text Roles

reStructuredText Interpreted Text Roles

Author: David Goodger
< > Author: Mark Nodine (for doctrip-specific implementation)
Contact: goodger@users.sourceforge.net< > ( mark.nodine@mot.com )
Revision: < > 1.11 2822
Date: < > 2005-04-19 2004-11-06 21:49:55 +0100 (Sat, 06 Nov 2004)
Copyright: This document has been placed in the public domain.

This document describes the interpreted text roles implemented in the reference reStructuredText parser.

Interpreted text uses backquotes (`) around the text. An explicit role marker may optionally appear before or after the text, delimited with colons. For example:

This is `interpreted text` using the default role.

This is :title:`interpreted text` using an explicit role.

A default role may be defined by applications of reStructuredText; it is used if no explicit :role: prefix or suffix is given. The "default default role" is :title-reference:.

See the Interpreted Text section in the reStructuredText Markup Specification for syntax details.< > For details on the hierarchy of elements, please see The Docutils Document Tree and the Docutils Generic DTD XML document type definition. For interpreted text role implementation details, see Creating reStructuredText Interpreted Text Roles.

Contents

Customization

< > No customization Custom interpreted text roles may be defined in a document with the "role" directive. Customization details are listed with each role.

A class option is recognized by the "role" directive for most interpreted text roles. A description is< > currently allowed. provided in the "role" directive documentation.

Standard Roles

:emphasis:

Aliases:None
DTD Element:emphasis
< > Customization:
Options:class.
Content:None.

Implements emphasis. These are equivalent:

*text*
:emphasis:`text`

:literal:

Aliases:None
DTD Element:literal
< > Customization:
Options:class.
Content:None.

Implements inline literal text. These are equivalent:

``text``
:literal:`text`

Care must be taken with backslash-escapes though. These are not equivalent:

``text \ and \ backslashes``
:literal:`text \ and \ backslashes`

The backslashes in the first line are preserved (and do nothing), whereas the backslashes in the second line escape the following spaces.

< > :bold: :pep-reference:

Aliases:< > :b: :PEP:
DTD Element:< > interpreted reference
< > Writers: Customization:< > html Implements bold text in html. :italic:
< > Aliases: Options:< > :i: class.
< > DTD Element: Content:< > interpreted None.
< > Writers:html
< > Implements italic text in html. :underline: Aliases: :u:
< > DTD Element:interpreted
Writers:html

< > Implements underlined text in html. The :pep-reference: role is used to create an HTTP reference to a PEP (Python Enhancement Proposal). The :PEP: alias is usually used. For example:

< >

See :PEP:`287` for more information about reStructuredText.

This is equivalent to:


See `PEP 287`__ for more information about reStructuredText.

__ http://www.python.org/peps/pep-0287.html

< > :strike: :rfc-reference:

Aliases:< > :s: :RFC:
DTD Element:< > interpreted reference
< > Writers: Customization:< > html Implements strikethrough text in html. :tt:
< > Aliases: Options:< > None class.
< > DTD Element: Content:< > interpreted None.
< > Writers:html
< > Implements tt text in html. :big: Aliases: None
< > DTD Element:interpreted
Writers:html

< > Implements big text in html. :small: Aliases: None DTD Element: interpreted Writers: html Implements small text in html. :color-<val>: The :rfc-reference:< > Aliases: None DTD Element: interpreted Writers: html Implements colored text in html. role is used to create an HTTP reference to an RFC (Internet Request for Comments). The< > <val> expresses the color that will be applied. :RFC: alias is usually used. For< > example example:

< >  This text is :color-red:`red`. See :RFC:`2822` for information about email headers.

< > results in This< > text is< > red . :size-<val>: Aliases: None DTD Element: interpreted Writers: html Implements text of different sizes in html. The <val> expresses the size that will be applied. For example equivalent to:

< >  This text is :size-18pt:`18 pt`. See `RFC 2822`__ for information about email headers.

__ http://www.faqs.org/rfcs/rfc2822.html

< > results in

This text is 18 pt.

< > :face-<val>: :strong:

Aliases:None
DTD Element:< > interpreted strong
< > Writers: Customization:< > html Implements text of different faces in html. The <val> expresses the face that will be applied. For example This text is :face-helvetica:`helvetica`. results in This text is helvetica . :class-<val>:
< > Aliases: Options:< > None class.
< > DTD Element: Content:< > interpreted None.
< > Writers:html
< > Implements text of different classes in html. The <val> expresses the class that will be applied. For example This text is :class-classy:`classy`. results in html like: This text is <class name="classy">classy</class>. You can affect how different classes are rendered using style sheets. :strong: Aliases: None
< > DTD Element:strong

Implements strong emphasis. These are equivalent:

**text**
:strong:`text`

:subscript:

Aliases::sub:
DTD Element:subscript
< > Customization:
Options:class.
Content:None.

Implements subscripts.

Tip

Whitespace or punctuation is required around interpreted text, but often not desired with subscripts & superscripts. Backslash-escaped whitespace can be used; the whitespace will be removed from the processed document:

H\ :sub:`2`\ O
E = mc\ :sup:`2`

In such cases, readability of the plain text can be greatly improved with substitutions:

The chemical formula for pure water is |H2O|.

.. |H2O| replace:: H\ :sub:`2`\ O

See the reStructuredText spec for further information on character-level markup and the substitution mechanism.

:superscript:

Aliases::sup:
DTD Element:superscript
< > Customization:
Options:class.
Content:None.

Implements superscripts. See the tip in :subscript: above.

:title-reference:

Aliases::title:, :t:.
DTD Element:< > interpreted title_reference
< > Customization:
Options:class.
Content:None.

The :title-reference: role is used to describe the titles of books, periodicals, and other materials. It is the equivalent of the HTML "cite" element, and it is expected that HTML writers will typically render "title_reference" elements using "cite".

Since title references are typically rendered with italics, they are often marked up using *emphasis*, which is misleading and vague. The "title_reference" element provides accurate and unambiguous descriptive markup.

Let's assume :title-reference: is the default interpreted text role (see below) for this example:

`Design Patterns` [GoF95]_ is an excellent read.

The following document fragment (pseudo-XML) will result from processing:

<paragraph>
< >  <interpreted role="title-reference">     <title_reference>
        Design Patterns

    <citation_reference refname="gof95">
        GoF95
     is an excellent read.

:title-reference: is the default interpreted text role in the standard reStructuredText parser. This means that no explicit role is required. Applications of reStructuredText may designate a different default role, in which case the explicit< > :title-reference: role must be< > used. used to obtain a title_reference element.

< > Specialized Roles

raw

Aliases:None
DTD Element:raw
Customization:
Options:class, format
Content:None

Warning

The "raw" role is a stop-gap measure allowing the author to bypass reStructuredText's markup. It is a "power-user" feature that should not be overused or abused. The use of "raw" ties documents to specific output formats and makes them less portable.

If you often need to use "raw"-derived interpreted text roles or the "raw" directive, that is a sign either of overuse/abuse or that functionality may be missing from reStructuredText. Please describe your situation in email to docutils-users@lists.sourceforge.net.

< >

The "raw" role indicates non-reStructuredText data that is to be passed untouched to the Writer. It is the inline equivalent of the "raw" directive; see its documentation for details on the semantics.

The "raw" role cannot be used directly. The "role" directive must first be used to build custom roles based on the "raw" role. One or more formats (Writer names) must be provided in a "format" option.

For example, the following creates an HTML-specific "raw-html" role:


.. role:: raw-html(raw)
   :format: html

This role can now be used directly to pass data untouched to the HTML Writer. For example:


If there just *has* to be a line break here,
:raw-html:`<br />`
it can be accomplished with a "raw"-derived role.
But the line block syntax should be considered first.

Tip

Roles based on "raw" should clearly indicate their origin, so they are not mistaken for reStructuredText markup. Using a "raw-" prefix for role names is recommended.

In addition to "class", the following option is recognized:

format : text
One or more space-separated output format names (Writer names).
< (73 differences)