diff options
author | Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> | 2018-01-04 22:13:29 +0300 |
---|---|---|
committer | Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> | 2018-01-06 18:52:12 +0300 |
commit | bf29ffb284f74b99adbc64d12b58ef4cef123af6 (patch) | |
tree | aad2d0525da202b0f14d8afbc5f622f324d7e2a7 /sphinx/jinja2glue.py | |
parent | c892fe98f7a311dc51340f8d98e63d9790b7f820 (diff) |
#4246: Limit width of text body for all themes
Diffstat (limited to 'sphinx/jinja2glue.py')
-rw-r--r-- | sphinx/jinja2glue.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index 8839e48fa..e6f49d18d 100644 --- a/sphinx/jinja2glue.py +++ b/sphinx/jinja2glue.py @@ -45,6 +45,25 @@ def _toint(val): return 0 +def _todim(val): + # type (int or unicode) -> unicode + """ + Make val a css dimension. In particular the following transformations + are performed: + + - None -> 'initial' (default CSS value) + - 0 -> '0' + - ints and string representations of ints are interpreted as pixels. + + Everything else is returned unchanged. + """ + if val is None: + return 'initial' + elif str(val).isdigit(): + return '0' if int(val) == 0 else '%spx' % val + return val + + def _slice_index(values, slices): # type: (List, int) -> Iterator[List] seq = list(values) @@ -164,6 +183,7 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader): extensions=extensions) self.environment.filters['tobool'] = _tobool self.environment.filters['toint'] = _toint + self.environment.filters['todim'] = _todim self.environment.filters['slice_index'] = _slice_index self.environment.globals['debug'] = contextfunction(pformat) self.environment.globals['accesskey'] = contextfunction(accesskey) |