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
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.
Trailing space:
After this method
_format_lines
still adds a\n
(which renders as a space again in the browser). To suppress that passlineseparator=''
to theInlineHtmlFormatter
class.