template¶
Note
This module requires html2text, Jinja2, and Pygments. pip
users can install them with the jnrbase[template] requirement.
Constants¶
-
jnrbase.template.FILTERS= {<name>: <filter function>, …}¶ Collection of custom filters to add to Jinja environment
Functions¶
-
jnrbase.template.jinja_filter(__func)[source]¶ Simple decorator to add a new filter to Jinja environment.
See also:
FILTERS
-
jnrbase.template.colourise(__text, *args, **kwargs)[source]¶ Colourise text using click’s style function.
Returns text untouched if colour output is not enabled, or
stdoutis not a tty.See
click.style()for parameters
-
jnrbase.template.highlight(__text, *, lexer='diff', formatter='terminal')[source]¶ Highlight text highlighted using
pygments.Returns text untouched if colour output is not enabled.
See also: Pygments
-
jnrbase.template.html2text(__html, *, width=80, ascii_replacements=False)[source]¶ HTML to plain text renderer.
See also: html2text
-
jnrbase.template.regexp(__string, __pattern, __repl, *, count=0, flags=0)[source]¶ Jinja filter for regexp replacements.
See
re.sub()for documentation.- Return type
- Returns
Text with substitutions applied
Examples¶
>>> FILTERS['regexp']('hello', 'l', 'L')
'heLLo'
>>> regexp('hello', 'l', 'L')
'heLLo'