calingen.templatetags.calingen_escape
¶
App-specific templatetags for escaping strings in templates.
Calingen is intended to support various types of layouts, meaning the app is able to support several target languages of templates (e.g. TeX, HTML, …).
Different target languages require different strings to be escaped. All of these are provided with this module.
Notes
The required regular expressions to escape strings are compiled at module level and may be re-used. This should boost performance during template processing.
An actual filter
for HTML is not provided, this should already be covered
by Django’s codebase.
Module Contents¶
Functions¶
|
Escape TeX control characters/sequences. |
Attributes¶
RegEx to find backslashes ( |
|
RegEx to find carets ( |
|
This RegEx is used to fix backslash escaping in TeX templates. |
|
RegEx to find a bunch of TeX special characters ( |
|
RegEx to find tildes ( |
|
- calingen.templatetags.calingen_escape.escape_tex(value)¶
Escape TeX control characters/sequences.
- Parameters:
value (str) – The string to be cleaned from TeX control sequences.
- Returns:
The cleaned / escaped string.
- Return type:
Notes
Special characters / sequences to be processed:
& % $ # _ { } ~ ^ \
The list of special TeX characters is taken from StackOverflow (see https://tex.stackexchange.com/a/34586). Actually, the same thread has the (Pearl) regular expressions to substitute these special characters aswell (see https://tex.stackexchange.com/a/119383).
- calingen.templatetags.calingen_escape.RE_BACKSLASH¶
RegEx to find backslashes (
\
).
- calingen.templatetags.calingen_escape.RE_EXP¶
RegEx to find carets (
^
).
- calingen.templatetags.calingen_escape.RE_TEX_BACKSLASH_FIX¶
This RegEx is used to fix backslash escaping in TeX templates.
- calingen.templatetags.calingen_escape.RE_TEX_CHARS¶
RegEx to find a bunch of TeX special characters (
$#&%_{}
).
- calingen.templatetags.calingen_escape.RE_TILDE¶
RegEx to find tildes (
~
).
- calingen.templatetags.calingen_escape.register¶