module documentation
(source)

This module defines standard interpreted text role functions, a registry for interpreted text roles, and an API for adding to and retrieving from the registry.

The interface for interpreted role functions is as follows:

def role_fn(name, rawtext, text, lineno, inliner,
            options={}, content=[]):
    code...

# Set function attributes for customization:
role_fn.options = ...
role_fn.content = ...

Parameters:

  • name is the local name of the interpreted text role, the role name actually used in the document.
  • rawtext is a string containing the entire interpreted text construct. Return it as a problematic node linked to a system message if there is a problem.
  • text is the interpreted text content, with backslash escapes converted to nulls (\).
  • lineno is the line number where the interpreted text beings.
  • inliner is the Inliner object that called the role function. It defines the following useful attributes: reporter, problematic, memo, parent, document.
  • options: A dictionary of directive options for customization, to be interpreted by the role function. Used for additional attributes for the generated elements and other functionality.
  • content: A list of strings, the directive content for customization ("role" directive). To be interpreted by the role function.

Function attributes for customization, interpreted by the "role" directive:

  • options: A dictionary, mapping known option names to conversion functions such as int or float. None or an empty dict implies no options to parse. Several directive option conversion functions are defined in the directives module.

    All role functions implicitly support the "class" option, unless disabled with an explicit {'class': None}.

  • content: A boolean; true if content is allowed. Client code must handle the case where content is required but not supplied (an empty content list will be supplied).

Note that unlike directives, the "arguments" function attribute is not supported for role customization. Directive arguments are handled by the "role" directive itself.

Interpreted role functions return a tuple of two values:

  • A list of nodes which will be inserted into the document tree at the point where the interpreted role was encountered (can be an empty list).
  • A list of system messages, which will be inserted into the document tree immediately after the end of the current inline block (can also be empty).
Class ​Custom​Role Wrapper for custom interpreted text roles.
Class ​Generic​Role Generic interpreted text role, where the interpreted text is simply wrapped with the provided node class.
Function code​_role Undocumented
Function generic​_custom​_role Undocumented
Function math​_role Undocumented
Function pep​_reference​_role Undocumented
Function raw​_role Undocumented
Function register​_canonical​_role Register an interpreted text role by its canonical name.
Function register​_generic​_role For roles which simply wrap a given node_class around the text.
Function register​_local​_role Register an interpreted text role by its local or language-dependent name.
Function rfc​_reference​_role Undocumented
Function role No summary
Function set​_classes Auxiliary function to set options['classes'] and delete options['class'].
Function set​_implicit​_options Add customization options to role functions, unless explicitly set or disabled.
Function unimplemented​_role Undocumented
Constant DEFAULT​_INTERPRETED​_ROLE The canonical name of the default interpreted role. This role is used when no role is specified for a piece of interpreted text.
Variable _role​_registry Mapping of canonical role names to role functions. Language-dependent role names are defined in the language subpackage.
Variable _roles Mapping of local or language-dependent interpreted text role names to role functions.
def code_role(role, rawtext, text, lineno, inliner, options={}, content=[]): (source)

Undocumented

def generic_custom_role(role, rawtext, text, lineno, inliner, options={}, content=[]): (source)

Undocumented

def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]): (source)

Undocumented

def pep_reference_role(role, rawtext, text, lineno, inliner, options={}, content=[]): (source)

Undocumented

def raw_role(role, rawtext, text, lineno, inliner, options={}, content=[]): (source)

Undocumented

def register_canonical_role(name, role_fn): (source)
Register an interpreted text role by its canonical name.
Parameters
nameThe canonical name of the interpreted role.
role​_fnThe role function. See the module docstring.
def register_generic_role(canonical_name, node_class): (source)
For roles which simply wrap a given node_class around the text.
def register_local_role(name, role_fn): (source)
Register an interpreted text role by its local or language-dependent name.
Parameters
nameThe local or language-dependent name of the interpreted role.
role​_fnThe role function. See the module docstring.
def rfc_reference_role(role, rawtext, text, lineno, inliner, options={}, content=[]): (source)

Undocumented

def role(role_name, language_module, lineno, reporter): (source)
Locate and return a role function from its language-dependent name, along with a list of system messages. If the role is not found in the current language, check English. Return a 2-tuple: role function (None if the named role cannot be found) and a list of system messages.
def set_classes(options): (source)
Auxiliary function to set options['classes'] and delete options['class'].
def set_implicit_options(role_fn): (source)
Add customization options to role functions, unless explicitly set or disabled.
def unimplemented_role(role, rawtext, text, lineno, inliner, attributes={}): (source)

Undocumented

DEFAULT_INTERPRETED_ROLE: str = (source)
The canonical name of the default interpreted role. This role is used when no role is specified for a piece of interpreted text.
Value
'title-reference'
_role_registry: dict = (source)
Mapping of canonical role names to role functions. Language-dependent role names are defined in the language subpackage.
_roles: dict = (source)
Mapping of local or language-dependent interpreted text role names to role functions.