Skip to content

Commit

Permalink
CSS: prompt protrudes into the left margin if wider than nbsphinx_pro…
Browse files Browse the repository at this point in the history
…mpt_width

Also, all theme-specific default values for nbsphinx_prompt_width
have been removed.
  • Loading branch information
mgeier committed Apr 21, 2020
1 parent 77f305b commit bba26b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 44 deletions.
2 changes: 2 additions & 0 deletions doc/usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@
"\n",
"Width of input/output prompts (HTML only).\n",
"\n",
"If a prompt is wider than that, it protrudes into the left margin.\n",
"\n",
"Any CSS length can be specified."
]
},
Expand Down
61 changes: 17 additions & 44 deletions src/nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,21 +485,33 @@
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
min-width: %(nbsphinx_prompt_width)s;
width: %(nbsphinx_prompt_width)s;
padding-top: 0.3rem;
padding-right: 0.3rem;
text-align: right;
flex: 0;
position: relative;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: %(nbsphinx_responsive_width)s) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars on prompts */
Expand Down Expand Up @@ -1733,44 +1745,6 @@ def patched_toctree_resolve(self, docname, builder, toctree, *args, **kwargs):


def config_inited(app, config):
# Set default value for CSS prompt width (optimized for two-digit numbers)
if config.nbsphinx_prompt_width is None:
config.nbsphinx_prompt_width = {
'agogo': '4.5ex',
'alabaster': '5.5ex',
'alabaster_jupyterhub': '5.5ex',
'basicstrap': '5.5ex',
'better': '4.5ex',
'bizstyle': '5.5ex',
'bootstrap': '5.5ex',
'bootstrap-astropy': '5.5ex',
'classic': '4.5ex',
'cloud': '5ex',
'dotted': '5ex',
'greencloud': '5ex',
'guzzle_sphinx_theme': '5.5ex',
'haiku': '4.5ex',
'julia': '5.5ex',
'jupyter': '5.5ex',
'maisie_sphinx_theme': '5.5ex',
'nature': '5ex',
'pandas_sphinx_theme': '5.5ex',
'pangeo': '5ex',
'pydata_sphinx_theme': '5.5ex',
'pyramid': '4.5ex',
'pytorch_sphinx_theme': '14ex',
'redcloud': '5ex',
'scrolls': '5.5ex',
'sizzle': '5ex',
'sphinxdoc': '5.5ex',
'sphinx_material': '5.5ex',
'sphinx_py3doc_enhanced_theme': '6.5ex',
'sphinx_pyviz_theme': '5.5ex',
'sphinx_rtd_theme': '5ex',
'sphinx_typlog_theme': '5.5ex',
'traditional': '5ex',
}.get(config.html_theme, '7ex')

for suffix in config.nbsphinx_custom_formats:
app.add_source_suffix(suffix, 'jupyter_notebook')

Expand Down Expand Up @@ -2115,8 +2089,7 @@ def setup(app):
app.add_config_value('nbsphinx_allow_errors', False, rebuild='')
app.add_config_value('nbsphinx_timeout', None, rebuild='')
app.add_config_value('nbsphinx_codecell_lexer', 'none', rebuild='env')
# Default value is set in config_inited():
app.add_config_value('nbsphinx_prompt_width', None, rebuild='html')
app.add_config_value('nbsphinx_prompt_width', '4.5ex', rebuild='html')
app.add_config_value('nbsphinx_responsive_width', '540px', rebuild='html')
app.add_config_value('nbsphinx_prolog', None, rebuild='env')
app.add_config_value('nbsphinx_epilog', None, rebuild='env')
Expand Down

0 comments on commit bba26b2

Please sign in to comment.