docutils.transforms.frontmatter module
Transforms related to the front matter of a document or a section (information found before the main text):
DocTitle: Used to transform a lone top level section’s title to the document title, promote a remaining lone top-level section’s title to the document subtitle, and determine the document’s title metadata (document[‘title’]) based on the document title and/or the “title” setting.
SectionSubTitle: Used to transform a lone subsection into a subtitle.
DocInfo: Used to transform a bibliographic field list into docinfo elements.
- class TitlePromoter(document, startnode=None)[source]
Bases:
TransformAbstract base class for DocTitle and SectionSubTitle transforms.
- promote_title(node)[source]
Transform the following tree:
<node> <section> <title> ...
into
<node> <title> ...
node is normally a document.
- class DocTitle(document, startnode=None)[source]
Bases:
TitlePromoterIn 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.
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.
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’]).
- default_priority = 320
Numerical priority of this transform, 0 through 999 (override).
- class SectionSubTitle(document, startnode=None)[source]
Bases:
TitlePromoterThis works like document subtitles, but for sections. For example,
<section> <title> Title <section> <title> Subtitle ...
is transformed into
<section> <title> Title <subtitle> Subtitle ...
For details refer to the docstring of DocTitle.
- default_priority = 350
Numerical priority of this transform, 0 through 999 (override).
- class DocInfo(document, startnode=None)[source]
Bases:
TransformThis transform is specific to the reStructuredText markup syntax; see “Bibliographic Fields” in the reStructuredText Markup Specification for a high-level description. This transform should be run after the DocTitle transform.
Given a field list as the first non-comment element after the document title and subtitle (if present), registered bibliographic field names are transformed to the corresponding DTD elements, becoming child elements of the “docinfo” element (except for a dedication and/or an abstract, which become “topic” elements after “docinfo”).
For example, given this document fragment after parsing:
<document> <title> Document Title <field_list> <field> <field_name> Author <field_body> <paragraph> A. Name <field> <field_name> Status <field_body> <paragraph> $RCSfile$ ...After running the bibliographic field list transform, the resulting document tree would look like this:
<document> <title> Document Title <docinfo> <author> A. Name <status> frontmatter.py ...
The “Status” field contained an expanded RCS keyword, which is normally (but optionally) cleaned up by the transform. The sole contents of the field body must be a paragraph containing an expanded RCS keyword of the form “$keyword: expansion text $”. Any RCS keyword can be processed in any bibliographic field. The dollar signs and leading RCS keyword name are removed. Extra processing is done for the following RCS keywords:
“RCSfile” expands to the name of the file in the RCS or CVS repository, which is the name of the source file with a “,v” suffix appended. The transform will remove the “,v” suffix.
“Date” expands to the format “YYYY/MM/DD hh:mm:ss” (in the UTC time zone). The RCS Keywords transform will extract just the date itself and transform it to an ISO 8601 format date, as in “2000-12-31”.
(Since the source file for this text is itself stored under CVS, we can’t show an example of the “Date” RCS keyword because we can’t prevent any RCS keywords used in this explanation from being expanded. Only the “RCSfile” keyword is stable; its expansion text changes only if the file name changes.)
- default_priority = 340
Numerical priority of this transform, 0 through 999 (override).
- biblio_nodes = {'abstract': <class 'docutils.nodes.topic'>, 'address': <class 'docutils.nodes.address'>, 'author': <class 'docutils.nodes.author'>, 'authors': <class 'docutils.nodes.authors'>, 'contact': <class 'docutils.nodes.contact'>, 'copyright': <class 'docutils.nodes.copyright'>, 'date': <class 'docutils.nodes.date'>, 'dedication': <class 'docutils.nodes.topic'>, 'organization': <class 'docutils.nodes.organization'>, 'revision': <class 'docutils.nodes.revision'>, 'status': <class 'docutils.nodes.status'>, 'version': <class 'docutils.nodes.version'>}
Canonical field name (lowcased) to node class name mapping for bibliographic fields (field_list).
- rcs_keyword_substitutions = [(re.compile('\\$Date: (\\d\\d\\d\\d)[-/](\\d\\d)[-/](\\d\\d)[ T][\\d:]+[^$]* \\$', re.IGNORECASE), '\\1-\\2-\\3'), (re.compile('\\$RCSfile: (.+),v \\$', re.IGNORECASE), '\\1'), (re.compile('\\$[a-zA-Z]+: (.+) \\$'), '\\1')]