Skip to content

Commit

Permalink
fix: correct ipynb code
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed May 26, 2024
1 parent f557784 commit 9e2056d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/views/layouts/jupynotex.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@


# basic verbatim start/end
VERBATIM_BEGIN = [r"\begin{footnotesize}", r"\begin{verbatim}"]
VERBATIM_END = [r"\end{verbatim}", r"\end{footnotesize}"]
VERBATIM_BEGIN = [r"\begin{minted}[fontsize=\footnotesize,breaklines,breakanywhere,tabsize=4]{md}"]
VERBATIM_END = [r"\end{minted}"]

# markdown start/end
MARKDOWN_BEGIN = [r"\begin{markdown}"]
MARKDOWN_END = [r"\end{markdown}"]

# highlighers for different languages (block beginning and ending)
HIGHLIGHTERS = {
'python': ([r'\begin{minted}[fontsize=\footnotesize]{python}'], [r'\end{minted}']),
'python': ([r'\begin{minted}[fontsize=\footnotesize,breaklines,breakanywhere,tabsize=4]{python}'], [r'\end{minted}']),
None: (VERBATIM_BEGIN, VERBATIM_END),
}

# the different formats to be used when error or all ok
FORMAT_ERROR = r"enhanced,breakable=unlimited,colback=red!5!white,colframe=red!75!"
FORMAT_OK = (
r"enhanced,breakable=unlimited,coltitle=red!75!black,colbacktitle=black!10!white, "
r"enhanced,breakable=unlimited,coltitle=red!75!black, colbacktitle=black!10!white, "
r"halign title=right, fonttitle=\sffamily\mdseries\scshape\footnotesize")

# a little mark to put in the continuation line(s) when text is wrapped
Expand Down Expand Up @@ -169,8 +173,8 @@ def __init__(self, path, config_options):
lang = nb_data['metadata']['language_info']['name']
self._highlight_delimiters = HIGHLIGHTERS.get(lang, HIGHLIGHTERS[None])

# get all cells excluding markdown ones
self._cells = [x for x in nb_data['cells'] if x['cell_type'] != 'markdown']
# get all cells
self._cells = [x for x in nb_data['cells']]

def _validate_config(self, config):
"""Validate received configuration."""
Expand Down Expand Up @@ -246,7 +250,7 @@ def get(self, cell_idx):
content = self._cells[cell_idx - 1]
source = self._proc_src(content)
output = self._proc_out(content)
return source, output
return source, output, content['cell_type'] == 'markdown'

def parse_cells(self, spec):
"""Convert the cells spec to a range of ints."""
Expand Down Expand Up @@ -298,7 +302,7 @@ def main(notebook_path, cells_spec, config_options):

for cell in cells:
try:
src, out = nb.get(cell)
src, out, md = nb.get(cell)
except Exception:
title = "ERROR when parsing cell {}".format(cell)
print(r"\begin{{tcolorbox}}[{}, title={{{}}}]".format(FORMAT_ERROR, title))
Expand Down

0 comments on commit 9e2056d

Please sign in to comment.