Skip to content

Commit bf29ffb

Browse files
committed
#4246: Limit width of text body for all themes
1 parent c892fe9 commit bf29ffb

File tree

17 files changed

+68
-16
lines changed

17 files changed

+68
-16
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Other contributors, listed alphabetically, are:
3434
* Horst Gutmann -- internationalization support
3535
* Martin Hans -- autodoc improvements
3636
* Doug Hellmann -- graphviz improvements
37+
* Tim Hoffmann -- theme improvements
3738
* Timotheus Kampik - JS theme & search enhancements
3839
* Dave Kuhlman -- original LaTeX writer
3940
* Blaise Laflamme -- pyramid theme

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Incompatible changes
1313
* #3929: apidoc: Move sphinx.apidoc to sphinx.ext.apidoc
1414
* #4226: apidoc: Generate new style makefile (make-mode)
1515
* #4274: sphinx-build returns 2 as an exit code on argument error
16+
* #4246: Limit width of text body for all themes. Conifigurable via theme
17+
options ``body_min_width`` and ``body_max_width``.
1618

1719
Deprecated
1820
----------

doc/theming.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,19 @@ These themes are:
114114
- **nosidebar** (true or false): Don't include the sidebar. Defaults to
115115
``False``.
116116

117-
- **sidebarwidth** (an integer): Width of the sidebar in pixels. (Do not
118-
include ``px`` in the value.) Defaults to 230 pixels.
117+
- **sidebarwidth** (int or str): Width of the sidebar in pixels.
118+
This can be an int, which is interpreted as pixels or a valid CSS
119+
dimension string such as '70em' or '50%'. Defaults to 230 pixels.
120+
121+
- **body_min_width** (int or str): Minimal width of the document body.
122+
This can be an int, which is interpreted as pixels or a valid CSS
123+
dimension string such as '70em' or '50%'. Use 0 if you don't want
124+
a width limit. Defaults may depend on the theme (often 450px).
125+
126+
- **body_max_width** (int or str): Maximal width of the document body.
127+
This can be an int, which is interpreted as pixels or a valid CSS
128+
dimension string such as '70em' or '50%'. Use 'none' if you don't
129+
want a width limit. Defaults may depend on the theme (often 800px).
119130

120131
* **alabaster** -- `Alabaster theme`_ is a modified "Kr" Sphinx theme from @kennethreitz
121132
(especially as used in his Requests project), which was itself originally based on

sphinx/jinja2glue.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ def _toint(val):
4545
return 0
4646

4747

48+
def _todim(val):
49+
# type (int or unicode) -> unicode
50+
"""
51+
Make val a css dimension. In particular the following transformations
52+
are performed:
53+
54+
- None -> 'initial' (default CSS value)
55+
- 0 -> '0'
56+
- ints and string representations of ints are interpreted as pixels.
57+
58+
Everything else is returned unchanged.
59+
"""
60+
if val is None:
61+
return 'initial'
62+
elif str(val).isdigit():
63+
return '0' if int(val) == 0 else '%spx' % val
64+
return val
65+
66+
4867
def _slice_index(values, slices):
4968
# type: (List, int) -> Iterator[List]
5069
seq = list(values)
@@ -164,6 +183,7 @@ def init(self, builder, theme=None, dirs=None):
164183
extensions=extensions)
165184
self.environment.filters['tobool'] = _tobool
166185
self.environment.filters['toint'] = _toint
186+
self.environment.filters['todim'] = _todim
167187
self.environment.filters['slice_index'] = _slice_index
168188
self.environment.globals['debug'] = contextfunction(pformat)
169189
self.environment.globals['accesskey'] = contextfunction(accesskey)

sphinx/themes/agogo/static/agogo.css_t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ div.document ol {
269269
/* Sidebar */
270270

271271
div.sidebar {
272-
width: {{ theme_sidebarwidth }};
272+
width: {{ theme_sidebarwidth|todim }};
273273
float: right;
274274
font-size: .9em;
275275
}

sphinx/themes/basic/static/basic.css_t

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ div.sphinxsidebarwrapper {
4949

5050
div.sphinxsidebar {
5151
float: left;
52-
width: {{ theme_sidebarwidth|toint }}px;
52+
width: {{ theme_sidebarwidth|todim }};
5353
margin-left: -100%;
5454
font-size: 90%;
5555
word-wrap: break-word;
@@ -199,6 +199,11 @@ table.modindextable td {
199199

200200
/* -- general body styles --------------------------------------------------- */
201201

202+
div.body {
203+
min-width: {{ theme_body_min_width|todim }};
204+
max-width: {{ theme_body_max_width|todim }};
205+
}
206+
202207
div.body p, div.body dd, div.body li, div.body blockquote {
203208
-moz-hyphens: auto;
204209
-ms-hyphens: auto;

sphinx/themes/basic/theme.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ sidebars = localtoc.html, relations.html, sourcelink.html, searchbox.html
77
[options]
88
nosidebar = false
99
sidebarwidth = 230
10+
body_min_width = 450
11+
body_max_width = 800
1012
navigation_with_keys = False

sphinx/themes/classic/static/classic.css_t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ div.documentwrapper {
3232
}
3333

3434
div.bodywrapper {
35-
margin: 0 0 0 {{ theme_sidebarwidth|toint }}px;
35+
margin: 0 0 0 {{ theme_sidebarwidth|todim }};
3636
}
3737

3838
div.body {
@@ -43,7 +43,7 @@ div.body {
4343

4444
{%- if theme_rightsidebar|tobool %}
4545
div.bodywrapper {
46-
margin: 0 {{ theme_sidebarwidth|toint }}px 0 0;
46+
margin: 0 {{ theme_sidebarwidth|todim }} 0 0;
4747
}
4848
{%- endif %}
4949

sphinx/themes/haiku/static/haiku.css_t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ body {
3434
margin: auto;
3535
padding: 0px;
3636
font-family: "DejaVu Sans", Arial, Helvetica, sans-serif;
37-
min-width: 59em;
38-
max-width: 70em;
37+
min-width: {{ theme_body_min_width|todim }};
38+
max-width: {{ theme_body_max_width|todim }};
3939
color: {{ theme_textcolor }};
4040
}
4141

sphinx/themes/haiku/theme.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pygments_style = autumn
55

66
[options]
77
full_logo = false
8+
body_min_width = 59em
9+
body_max_width = 70em
810
textcolor = #333333
911
headingcolor = #0c3762
1012
linkcolor = #dc3c01

sphinx/themes/nature/static/nature.css_t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ div.documentwrapper {
2828
}
2929

3030
div.bodywrapper {
31-
margin: 0 0 0 {{ theme_sidebarwidth|toint }}px;
31+
margin: 0 0 0 {{ theme_sidebarwidth|todim }};
3232
}
3333

3434
hr {

sphinx/themes/pyramid/static/pyramid.css_t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ div.documentwrapper {
2828
}
2929

3030
div.bodywrapper {
31-
margin: 0 0 0 {{ theme_sidebarwidth }}px;
31+
margin: 0 0 0 {{ theme_sidebarwidth|todim }};
3232
}
3333

3434
hr {
@@ -92,7 +92,7 @@ div.related a {
9292
}
9393

9494
div.related ul {
95-
padding-left: {{ theme_sidebarwidth|toint + 10 }}px;
95+
padding-left: calc({{ theme_sidebarwidth|todim }} + 10px);
9696
}
9797

9898
div.sphinxsidebar {

sphinx/themes/scrolls/static/scrolls.css_t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ h1.heading span {
9898
}
9999

100100
#contentwrapper {
101-
max-width: 680px;
101+
min-width: {{ theme_body_min_width|todim }};
102+
max-width: {{ theme_body_max_width|todim }};
102103
padding: 0 18px 20px 18px;
103104
margin: 0 auto 0 auto;
104105
border-right: 1px solid #eee;

sphinx/themes/scrolls/theme.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ stylesheet = scrolls.css
44
pygments_style = tango
55

66
[options]
7+
body_min_width = 0
8+
body_max_width = 680
79
headerbordercolor = #1752b4
810
subheadlinecolor = #0d306b
911
linkcolor = #1752b4

sphinx/themes/sphinxdoc/static/sphinxdoc.css_t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ div.document {
3838
}
3939

4040
div.bodywrapper {
41-
margin: 0 {{ theme_sidebarwidth|toint + 10 }}px 0 0;
41+
margin: 0 calc({{ theme_sidebarwidth|todim }} + 10px) 0 0;
4242
border-right: 1px solid #ccc;
4343
}
4444

@@ -88,7 +88,7 @@ div.sphinxsidebarwrapper {
8888
div.sphinxsidebar {
8989
margin: 0;
9090
padding: 0.5em 15px 15px 0;
91-
width: {{ theme_sidebarwidth|toint - 20 }}px;
91+
width: calc({{ theme_sidebarwidth|todim }} - 20px);
9292
float: right;
9393
font-size: 1em;
9494
text-align: left;

sphinx/themes/traditional/static/traditional.css_t

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ div.documentwrapper {
2323
}
2424

2525
div.bodywrapper {
26-
margin: 0 {{ theme_sidebarwidth }}px 0 0;
26+
margin: 0 {{ theme_sidebarwidth|todim }} 0 0;
2727
}
2828

2929
div.body {
30+
min-width: {{ theme_body_min_width|todim }};
31+
max-width: {{ theme_body_max_width|todim }};
3032
background-color: white;
3133
padding: 0 20px 30px 20px;
3234
}
@@ -40,7 +42,7 @@ div.sphinxsidebarwrapper {
4042
div.sphinxsidebar {
4143
float: right;
4244
margin-left: -100%;
43-
width: {{ theme_sidebarwidth }}px;
45+
width: {{ theme_sidebarwidth|todim }};
4446
}
4547

4648
div.clearer {

sphinx/themes/traditional/theme.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[theme]
22
inherit = basic
33
stylesheet = traditional.css
4+
5+
[options]
6+
body_min_width = 0
7+
body_max_width = none

0 commit comments

Comments
 (0)