##// END OF EJS Templates
Backport PR #5459: Fix interact animation page jump FF...
Backport PR #5459: Fix interact animation page jump FF Firefox doesn't render images immediately as the data is available. When animating the way that we animate, this causes the output area to collapse quickly before returning to its original size. When the output area collapses, FireFox scrolls upwards in attempt to compensate for the lost vertical content (so it looks like you are on the same spot in the page, with respect to the contents below the image's prior location). The solution is to resize the image output after the `img onload` event has fired. This PR: - Releases the `clear_output` height lock after the image has been loaded (instead of immediately or using a timeout). - Removes a `setTimeout` call in the `append_output` method. - `clear_output` in zmqshell no longer sends `\r` to the stream outputs. closes #5128

File last commit:

r14750:7d9f8d99
r16229:ff1462d3
Show More
csshtmlheader.py
106 lines | 3.1 KiB | text/x-python | PythonLexer
"""Module that pre-processes the notebook for export to HTML.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
import io
from IPython.utils import path
from .base import Preprocessor
from IPython.utils.traitlets import Unicode
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
class CSSHTMLHeaderPreprocessor(Preprocessor):
"""
Preprocessor used to pre-process notebook for HTML output. Adds IPython notebook
front-end CSS and Pygments CSS to HTML output.
"""
header = []
highlight_class = Unicode('.highlight', config=True,
help="CSS highlight class identifier")
def __init__(self, config=None, **kw):
"""
Public constructor
Parameters
----------
config : Config
Configuration file structure
**kw : misc
Additional arguments
"""
super(CSSHTMLHeaderPreprocessor, self).__init__(config=config, **kw)
if self.enabled :
self._regen_header()
def preprocess(self, nb, resources):
"""Fetch and add CSS to the resource dictionary
Fetch CSS from IPython and Pygments to add at the beginning
of the html files. Add this css in resources in the
"inlining.css" key
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jinja engine.
"""
resources['inlining'] = {}
resources['inlining']['css'] = self.header
return nb, resources
def _regen_header(self):
"""
Fills self.header with lines of CSS extracted from IPython
and Pygments.
"""
from pygments.formatters import HtmlFormatter
#Clear existing header.
header = []
#Construct path to IPy CSS
from IPython.html import DEFAULT_STATIC_FILES_PATH
sheet_filename = os.path.join(DEFAULT_STATIC_FILES_PATH,
'style', 'style.min.css')
#Load style CSS file.
with io.open(sheet_filename, encoding='utf-8') as file:
file_text = file.read()
header.append(file_text)
#Add pygments CSS
formatter = HtmlFormatter()
pygments_css = formatter.get_style_defs(self.highlight_class)
header.append(pygments_css)
#Set header
self.header = header