lib.roles.transforms.code

Code related formatter and transformers.

class django_docutils.lib.transforms.code.InlineHtmlFormatter(**options)[source]

Bases: HtmlFormatter

HTMLFormatter for inline codeblocks.

format_unencoded(tokensource, outfile)[source]

Trim inline element of space and newlines. :rtype: None

  1. Trailing newline: Final token generated returns (Token.Other, '\n') results in a blank space <span class="x"></span>.

    This would be unnoticeable for a code block, but as this is inline, it looks strange. Let’s filter out any trailing newlines from token source, then fallback to the normal process by passing it back into parent class method.

  2. Trailing space:

    After this method _format_lines still adds a \n (which renders as a space again in the browser). To suppress that pass lineseparator='' to the InlineHtmlFormatter class.

_wrap_div(inner)[source]
Return type:

Union[TokenGenerator, TokenStream]

_wrap_pre(inner)[source]
Return type:

TokenStream

class django_docutils.lib.transforms.code.CodeTransform(document, startnode=None)[source]

Bases: Transform

Run over unparsed literals and try to guess language + highlight.

default_priority = 120

Numerical priority of this transform, 0 through 999 (override).

apply(**kwargs)[source]

Apply CodeTransform.

Return type:

None