def substitution_code_role(
        *args, **kwargs) -> Tuple[List[Node], List[system_message]]:
    """Decorate an inline code so that SubstitutionCodeBlockTransform will notice it"""
    [node], system_messages = code_role(*args, **kwargs)
    node[_SUBSTITUTION_OPTION_NAME] = True

    return [node], system_messages
Exemple #2
0
    def substitution_code_role(  # pylint: disable=dangerous-default-value
        typ: str,
        rawtext: str,
        text: str,
        lineno: int,
        inliner: Inliner,
        options: Dict = {},
        content: List[str] = [],
    ) -> Tuple[List[Node], List[system_message]]:
        """
        Replace placeholders with given variables.
        """
        app_config = app.config  # type: ignore
        substitutions: Tuple[str, str] = app_config.substitutions
        for pair in substitutions:
            original, replacement = pair
            text = text.replace(original, replacement)
            rawtext = rawtext.replace(original, replacement)

        result_nodes, system_messages = code_role(
            role=typ,
            rawtext=rawtext,
            text=text,
            lineno=lineno,
            inliner=inliner,
            options=options,
            content=content,
        )

        return result_nodes, system_messages
def substitution_code_role(  # pylint: disable=dangerous-default-value
    typ: str,
    rawtext: str,
    text: str,
    lineno: int,
    inliner: Inliner,
    options: Dict = {},
    content: list[str] = [],
) -> Tuple[list[Node], list[system_message]]:
    """
    Replace placeholders with given variables.
    """
    document = inliner.document  # type: ignore
    for name, value in document.substitution_defs.items():
        replacement = value.astext()
        text = text.replace(f'|{name}|', replacement)
        rawtext = text.replace(f'|{name}|', replacement)
        rawtext = rawtext.replace(name, replacement)

    result_nodes, system_messages = code_role(
        role=typ,
        rawtext=rawtext,
        text=text,
        lineno=lineno,
        inliner=inliner,
        options=options,
        content=content,
    )

    return result_nodes, system_messages
def python_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    options = {'language': 'python'}
    return code_role(role,
                     rawtext,
                     text,
                     lineno,
                     inliner,
                     options=options,
                     content=content)
Exemple #5
0
def bash_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    """A role to create inline code that is highlighted using the Bash lexer."""
    options.update({'classes': ['inline-code'], 'language': 'bash'})
    return roles.code_role(name,
                           rawtext,
                           text,
                           lineno,
                           inliner,
                           options=options)
Exemple #6
0
def coq_code_role(role,
                  rawtext,
                  text,
                  lineno,
                  inliner,
                  options={},
                  content=[]):
    options = {**options.copy(), "language": "coq", "classes": "highlight"}
    return roles.code_role(role, rawtext, text, lineno, inliner, options,
                           content)
Exemple #7
0
def coq_code_role(role,
                  rawtext,
                  text,
                  lineno,
                  inliner,
                  options={},
                  content=[]):
    #pylint: disable=dangerous-default-value
    """And inline role for Coq source code"""
    options['language'] = 'Coq'
    return code_role(role, rawtext, text, lineno, inliner, options, content)
Exemple #8
0
def coq_code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    #pylint: disable=dangerous-default-value
    """Coq code.

    Use this for Gallina and Ltac snippets::

       :g:`apply plus_comm; reflexivity`
       :g:`Set Printing All.`
       :g:`forall (x: t), P(x)`
    """
    options['language'] = 'Coq'
    return code_role(role, rawtext, text, lineno, inliner, options, content)
Exemple #9
0
def coq_code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    #pylint: disable=dangerous-default-value
    """Coq code.

    Use this for Gallina and Ltac snippets::

       :g:`apply plus_comm; reflexivity`
       :g:`Set Printing All.`
       :g:`forall (x: t), P(x)`
    """
    options['language'] = 'Coq'
    return code_role(role, rawtext, text, lineno, inliner, options, content)
Exemple #10
0
def coq_code_role(role,
                  rawtext,
                  text,
                  lineno,
                  inliner,
                  options={},
                  content=[]):
    options = {**options, "language": "coq"}
    roles.set_classes(options)
    options.setdefault("classes", []).append("highlight")
    return roles.code_role(role, rawtext, text, lineno, inliner, options,
                           content)
def bash_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
  """A role to create inline code that is highlighted using the Bash lexer."""
  options.update({'classes': ['inline-code'], 'language': 'bash'})
  return roles.code_role(name, rawtext, text, lineno, inliner, options=options)
Exemple #12
0
def coq_code_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    #pylint: disable=dangerous-default-value
    """And inline role for Coq source code"""
    options['language'] = 'Coq'
    return code_role(role, rawtext, text, lineno, inliner, options, content)
def python_role(role, rawtext, text, lineno,
                inliner, options={}, content=[]):
    options = {'language': 'python'}
    return code_role(role, rawtext, text, lineno,
                     inliner, options=options, content=content)