Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Adding support for nbconvert configuration (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
croach authored and danielfrg committed Aug 4, 2018
1 parent a807798 commit 719cb7b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
# IPython < 2.0
from nbconvert.filters.highlight import _pygments_highlight

try:
from nbconvert.nbconvertapp import NbConvertApp
except ImportError:
from IPython.nbconvert.nbconvertapp import NbConvertApp

try:
from bs4 import BeautifulSoup
except:
BeautifulSoup = None

from pygments.formatters import HtmlFormatter

from copy import deepcopy


LATEX_CUSTOM_SCRIPT = """
<script type="text/javascript">if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
Expand Down Expand Up @@ -74,6 +88,14 @@
"""


def get_config():
"""Load and return the user's nbconvert configuration
"""
app = NbConvertApp()
app.load_config_file()
return app.config


def get_html_from_filepath(filepath, start=0, end=None, preprocessors=[], template=None):
"""Return the HTML from a Jupyter Notebook
"""
Expand All @@ -83,7 +105,8 @@ def get_html_from_filepath(filepath, start=0, end=None, preprocessors=[], templa
extra_loaders.append(jinja2.FileSystemLoader([os.path.dirname(template)]))
template_file = os.path.basename(template)

config = Config({'CSSHTMLHeaderTransformer': {
config = get_config()
config.update({'CSSHTMLHeaderTransformer': {
'enabled': True,
'highlight_class': '.highlight-ipynb'},
'SubCell': {
Expand Down

0 comments on commit 719cb7b

Please sign in to comment.