本文整理匯總了Python中nbconvert.exporters.HTMLExporter方法的典型用法代碼示例。如果您正苦於以下問題:Python exporters.HTMLExporter方法的具體用法?Python exporters.HTMLExporter怎麽用?Python exporters.HTMLExporter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nbconvert.exporters
的用法示例。
在下文中一共展示了exporters.HTMLExporter方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _process
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def _process(self):
config = Config()
config.HTMLExporter.preprocessors = [CppHighlighter]
config.HTMLExporter.template_file = 'basic'
with self.attachment.file.open() as f:
notebook = nbformat.read(f, as_version=4)
html_exporter = HTMLExporter(config=config)
body, resources = html_exporter.from_notebook_node(notebook)
css_code = '\n'.join(resources['inlining'].get('css', []))
nonce = str(uuid4())
html = render_template('previewer_jupyter:ipynb_preview.html', attachment=self.attachment,
html_code=body, css_code=css_code, nonce=nonce)
response = current_app.response_class(html)
# Use CSP to restrict access to possibly malicious scripts or inline JS
csp_header = "script-src cdn.mathjax.org 'nonce-{}';".format(nonce)
response.headers['Content-Security-Policy'] = csp_header
response.headers['X-Webkit-CSP'] = csp_header
# IE10 doesn't have proper CSP support, so we need to be more strict
response.headers['X-Content-Security-Policy'] = "sandbox allow-same-origin;"
return response
示例2: convert_notebook
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def convert_notebook(ramp_kit_dir='.'):
import nbformat
import nbconvert
from nbconvert.exporters import HTMLExporter
problem_name = os.path.basename(os.path.abspath(ramp_kit_dir))
print('Testing if the notebook can be converted to html')
notebook_filename = os.path.join(
os.path.abspath(ramp_kit_dir),
'{}_starting_kit.ipynb'.format(problem_name))
notebook_html_filename = os.path.join(
os.path.abspath(ramp_kit_dir),
'{}_starting_kit.html'.format(problem_name))
with open(notebook_filename) as f:
nb = nbformat.read(f, as_version=4)
nb_html, _ = nbconvert.export(HTMLExporter, nb)
with open(os.path.join(os.path.abspath(ramp_kit_dir),
notebook_html_filename), 'wb') as f:
f.write(nb_html.encode('utf-8'))
delete_line_from_file(
notebook_html_filename,
'<link rel="stylesheet" href="custom.css">\n')
示例3: render_ipynb
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def render_ipynb(full_path, format):
"""
Render a given ipynb file
"""
exporter = HTMLExporter()
with open(full_path, encoding='utf-8') as file_handle:
html, res = exporter.from_file(file_handle)
return Response(html, mimetype='text/html')
# Map of extensions to functions to call for handling them
示例4: convert_ipynb_to_html
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def convert_ipynb_to_html(notebook_file, html_file):
"""
Convert the given Jupyter notebook file (``.ipynb``)
to HTML and write it out as the given ``.html`` file.
Parameters
----------
notebook_file : str
Path to input Jupyter notebook file.
html_file : str
Path to output HTML file.
Note
----
This function is also exposed as the
:ref:`render_notebook <render_notebook>` command-line utility.
"""
# set a high timeout for datasets with a large number of features
report_config = Config({'ExecutePreprocessor': {'enabled': True,
'timeout': 3600},
'HTMLExporter': {'template_path': [template_path],
'template_file': 'report.tpl'}})
exportHtml = HTMLExporter(config=report_config)
output, _ = exportHtml.from_filename(notebook_file)
open(html_file, mode='w', encoding='utf-8').write(output)
示例5: post
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def post(self):
defined = []
for v in self.application.parameters:
if v.type is bool:
inp = v.with_value(self.get_argument(v.name, default='off') == 'on')
else:
inp = v.with_value(v.type(self.get_argument(v.name)))
defined.append(inp)
res = {'path': os.path.dirname(self.application.path)}
nb = replace_definitions(
self.application.nb, defined, execute=True, execute_resources=res
)
output, _ = HTMLExporter().from_notebook_node(nb, res)
self.write(output)
示例6: _classes_default
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def _classes_default(self):
classes = super(FormgradeExtension, self)._classes_default()
classes.append(HTMLExporter)
return classes
示例7: build_extra_config
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def build_extra_config(self):
extra_config = super(FormgradeExtension, self).build_extra_config()
extra_config.HTMLExporter.template_file = 'formgrade'
extra_config.HTMLExporter.template_path = [handlers.template_path]
return extra_config
示例8: init_tornado_settings
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def init_tornado_settings(self, webapp):
# Init jinja environment
jinja_env = Environment(loader=FileSystemLoader([handlers.template_path]))
course_dir = self.coursedir.root
notebook_dir = self.parent.notebook_dir
relpath = os.path.relpath(course_dir, notebook_dir)
if relpath.startswith("../"):
nbgrader_bad_setup = True
self.log.error(
"The course directory root is not a subdirectory of the notebook "
"server root. This means that nbgrader will not work correctly. "
"If you want to use nbgrader, please ensure the course directory "
"root is in a subdirectory of the notebook root: %s", notebook_dir)
else:
nbgrader_bad_setup = False
# Configure the formgrader settings
tornado_settings = dict(
nbgrader_url_prefix=os.path.relpath(self.coursedir.root, self.parent.notebook_dir),
nbgrader_coursedir=self.coursedir,
nbgrader_authenticator=self.authenticator,
nbgrader_exporter=HTMLExporter(config=self.config),
nbgrader_gradebook=None,
nbgrader_db_url=self.coursedir.db_url,
nbgrader_jinja2_env=jinja_env,
nbgrader_bad_setup=nbgrader_bad_setup
)
webapp.settings.update(tornado_settings)
示例9: _classes_default
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def _classes_default(self):
classes = super(GenerateFeedback, self)._classes_default()
classes.append(HTMLExporter)
return classes
示例10: __init__
# 需要導入模塊: from nbconvert import exporters [as 別名]
# 或者: from nbconvert.exporters import HTMLExporter [as 別名]
def __init__(self, coursedir=None, **kwargs):
super(GenerateFeedback, self).__init__(coursedir=coursedir, **kwargs)
c = Config()
if 'template_file' not in self.config.HTMLExporter:
c.HTMLExporter.template_file = 'feedback.tpl'
if 'template_path' not in self.config.HTMLExporter:
template_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'server_extensions', 'formgrader', 'templates'))
c.HTMLExporter.template_path = ['.', template_path]
self.update_config(c)