class documentation

class DocTitle(TitlePromoter): (source)

View In Hierarchy

In reStructuredText, there is no way to specify a document title and subtitle explicitly. Instead, we can supply the document title (and possibly the subtitle as well) implicitly, and use this two-step transform to "raise" or "promote" the title(s) (and their corresponding section contents) to the document level.

  1. If the document contains a single top-level section as its first non-comment element, the top-level section's title becomes the document's title, and the top-level section's contents become the document's immediate contents. The lone top-level section header must be the first non-comment element in the document.

    For example, take this input text:

    =================
     Top-Level Title
    =================
    
    A paragraph.
    

    Once parsed, it looks like this:

    <document>
        <section names="top-level title">
            <title>
                Top-Level Title
            <paragraph>
                A paragraph.
    

    After running the DocTitle transform, we have:

    <document names="top-level title">
        <title>
            Top-Level Title
        <paragraph>
            A paragraph.
    
  2. If step 1 successfully determines the document title, we continue by checking for a subtitle.

    If the lone top-level section itself contains a single second-level section as its first non-comment element, that section's title is promoted to the document's subtitle, and that section's contents become the document's immediate contents. Given this input text:

    =================
     Top-Level Title
    =================
    
    Second-Level Title
    ~~~~~~~~~~~~~~~~~~
    
    A paragraph.
    

    After parsing and running the Section Promotion transform, the result is:

    <document names="top-level title">
        <title>
            Top-Level Title
        <subtitle names="second-level title">
            Second-Level Title
        <paragraph>
            A paragraph.
    

    (Note that the implicit hyperlink target generated by the "Second-Level Title" is preserved on the "subtitle" element itself.)

Any comment elements occurring before the document title or subtitle are accumulated and inserted as the first body elements after the title(s).

This transform also sets the document's metadata title (document['title']).

Method apply Override to apply the transform to the document tree.
Method set​_metadata Set document['title'] metadata title from the following sources, listed in order of priority:
Class Variable default​_priority Numerical priority of this transform, 0 through 999 (override).

Inherited from TitlePromoter:

Method candidate​_index Find and return the promotion candidate and its index.
Method promote​_subtitle Transform the following node tree:
Method promote​_title Transform the following tree:

Inherited from Transform (via TitlePromoter):

Method __init__ Initial setup for in-place document transforms.
Instance Variable document The document tree to transform.
Instance Variable language Language module local to this document.
Instance Variable startnode Node from which to begin the transform. For many transforms which apply to the document as a whole, startnode is not set (i.e. its value is None).
def apply(self): (source)
Override to apply the transform to the document tree.
def set_metadata(self): (source)

Set document['title'] metadata title from the following sources, listed in order of priority:

  • Existing document['title'] attribute.
  • "title" setting.
  • Document title node (as promoted by promote_title).
default_priority: int = (source)
Numerical priority of this transform, 0 through 999 (override).