code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def ansi2html(text):
"""
Convert ANSI colors to HTML colors.
Parameters
----------
text : unicode
Text containing ANSI colors to convert to HTML
"""
text = markupsafe.escape(text)
return _ansi2anything(text, _htmlconverter) |
Convert ANSI colors to HTML colors.
Parameters
----------
text : unicode
Text containing ANSI colors to convert to HTML
| ansi2html | python | jupyter/nbconvert | nbconvert/filters/ansi.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/ansi.py | BSD-3-Clause |
def _htmlconverter(fg, bg, bold, underline, inverse):
"""
Return start and end tags for given foreground/background/bold/underline.
"""
if (fg, bg, bold, underline, inverse) == (None, None, False, False, False):
return "", ""
classes = []
styles = []
if inverse:
fg, bg = b... |
Return start and end tags for given foreground/background/bold/underline.
| _htmlconverter | python | jupyter/nbconvert | nbconvert/filters/ansi.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/ansi.py | BSD-3-Clause |
def _latexconverter(fg, bg, bold, underline, inverse):
"""
Return start and end markup given foreground/background/bold/underline.
"""
if (fg, bg, bold, underline, inverse) == (None, None, False, False, False):
return "", ""
starttag, endtag = "", ""
if inverse:
fg, bg = bg, f... |
Return start and end markup given foreground/background/bold/underline.
| _latexconverter | python | jupyter/nbconvert | nbconvert/filters/ansi.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/ansi.py | BSD-3-Clause |
def _ansi2anything(text, converter):
r"""
Convert ANSI colors to HTML or LaTeX.
See https://en.wikipedia.org/wiki/ANSI_escape_code
Accepts codes like '\x1b[32m' (red) and '\x1b[1;32m' (bold, red).
Non-color escape sequences (not ending with 'm') are filtered out.
Ideally, this should have th... |
Convert ANSI colors to HTML or LaTeX.
See https://en.wikipedia.org/wiki/ANSI_escape_code
Accepts codes like '\x1b[32m' (red) and '\x1b[1;32m' (bold, red).
Non-color escape sequences (not ending with 'm') are filtered out.
Ideally, this should have the same behavior as the function
fixConsol... | _ansi2anything | python | jupyter/nbconvert | nbconvert/filters/ansi.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/ansi.py | BSD-3-Clause |
def citation2latex(s):
"""Parse citations in Markdown cells.
This looks for HTML tags having a data attribute names ``data-cite``
and replaces it by the call to LaTeX cite command. The transformation
looks like this::
<cite data-cite="granger">(Granger, 2013)</cite>
Becomes ::
\\... | Parse citations in Markdown cells.
This looks for HTML tags having a data attribute names ``data-cite``
and replaces it by the call to LaTeX cite command. The transformation
looks like this::
<cite data-cite="granger">(Granger, 2013)</cite>
Becomes ::
\cite{granger}
Any HTML tag... | citation2latex | python | jupyter/nbconvert | nbconvert/filters/citation.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/citation.py | BSD-3-Clause |
def __call__(self, output):
"""Return the first available format in the priority.
Produces a UserWarning if no compatible mimetype is found.
`output` is dict with structure {mimetype-of-element: value-of-element}
"""
for fmt in self.display_data_priority:
if fmt in... | Return the first available format in the priority.
Produces a UserWarning if no compatible mimetype is found.
`output` is dict with structure {mimetype-of-element: value-of-element}
| __call__ | python | jupyter/nbconvert | nbconvert/filters/datatypefilter.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/datatypefilter.py | BSD-3-Clause |
def resolve_one_reference(key, val, fmt, meta):
"""
This takes a tuple of arguments that are compatible with ``pandocfilters.walk()`` that
allows identifying hyperlinks in the document and transforms them into valid LaTeX
\\hyperref{} calls so that linking to headers between cells is possible.
See ... |
This takes a tuple of arguments that are compatible with ``pandocfilters.walk()`` that
allows identifying hyperlinks in the document and transforms them into valid LaTeX
\hyperref{} calls so that linking to headers between cells is possible.
See the documentation in ``pandocfilters.walk()`` for furthe... | resolve_one_reference | python | jupyter/nbconvert | nbconvert/filters/filter_links.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/filter_links.py | BSD-3-Clause |
def __call__(self, source, language=None, metadata=None):
"""
Return a syntax-highlighted version of the input source as html output.
Parameters
----------
source : str
source of the cell to highlight
language : str
language to highlight the synta... |
Return a syntax-highlighted version of the input source as html output.
Parameters
----------
source : str
source of the cell to highlight
language : str
language to highlight the syntax of
metadata : NotebookNode cell metadata
metada... | __call__ | python | jupyter/nbconvert | nbconvert/filters/highlight.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/highlight.py | BSD-3-Clause |
def __call__(self, source, language=None, metadata=None, strip_verbatim=False):
"""
Return a syntax-highlighted version of the input source as latex output.
Parameters
----------
source : str
source of the cell to highlight
language : str
language... |
Return a syntax-highlighted version of the input source as latex output.
Parameters
----------
source : str
source of the cell to highlight
language : str
language to highlight the syntax of
metadata : NotebookNode cell metadata
metad... | __call__ | python | jupyter/nbconvert | nbconvert/filters/highlight.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/highlight.py | BSD-3-Clause |
def _pygments_highlight(
source, output_formatter, language="ipython", metadata=None, **lexer_options
):
"""
Return a syntax-highlighted version of the input source
Parameters
----------
source : str
source of the cell to highlight
output_formatter : Pygments formatter
language ... |
Return a syntax-highlighted version of the input source
Parameters
----------
source : str
source of the cell to highlight
output_formatter : Pygments formatter
language : str
language to highlight the syntax of
metadata : NotebookNode cell metadata
metadata of the ... | _pygments_highlight | python | jupyter/nbconvert | nbconvert/filters/highlight.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/highlight.py | BSD-3-Clause |
def escape_latex(text):
"""
Escape characters that may conflict with latex.
Parameters
----------
text : str
Text containing characters that may conflict with Latex
"""
text = "".join(LATEX_SUBS.get(c, c) for c in text)
for pattern, replacement in LATEX_RE_SUBS:
text = p... |
Escape characters that may conflict with latex.
Parameters
----------
text : str
Text containing characters that may conflict with Latex
| escape_latex | python | jupyter/nbconvert | nbconvert/filters/latex.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/latex.py | BSD-3-Clause |
def markdown2html_pandoc(source, extra_args=None):
"""
Convert a markdown string to HTML via pandoc.
"""
extra_args = extra_args or ["--mathjax"]
return convert_pandoc(source, _MARKDOWN_FMT, "html", extra_args=extra_args) |
Convert a markdown string to HTML via pandoc.
| markdown2html_pandoc | python | jupyter/nbconvert | nbconvert/filters/markdown.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown.py | BSD-3-Clause |
def markdown2asciidoc(source, extra_args=None):
"""Convert a markdown string to asciidoc via pandoc"""
# Prior to version 3.0, pandoc supported the --atx-headers flag.
# For later versions, we must instead pass --markdown-headings=atx.
# See https://pandoc.org/releases.html#pandoc-3.0-2023-01-18
at... | Convert a markdown string to asciidoc via pandoc | markdown2asciidoc | python | jupyter/nbconvert | nbconvert/filters/markdown.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown.py | BSD-3-Clause |
def parse_multiline_math(self, m: Match[str], state: BlockState) -> int:
"""Send mutiline math as a single paragraph to MathInlineParser."""
matched_text = m[0]
state.add_paragraph(matched_text)
return m.end() | Send mutiline math as a single paragraph to MathInlineParser. | parse_multiline_math | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def parse_block_math_tex(self, m: Match[str], state: InlineState) -> int:
"""Parse older TeX-style display math."""
body = m.group("math_block_tex")
state.append_token({"type": "block_math", "raw": body})
return m.end() | Parse older TeX-style display math. | parse_block_math_tex | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def parse_block_math_latex(self, m: Match[str], state: InlineState) -> int:
"""Parse newer LaTeX-style display math."""
body = m.group("math_block_latex")
state.append_token({"type": "block_math", "raw": body})
return m.end() | Parse newer LaTeX-style display math. | parse_block_math_latex | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def parse_inline_math_tex(self, m: Match[str], state: InlineState) -> int:
"""Parse older TeX-style inline math."""
body = m.group("math_inline_tex")
state.append_token({"type": "inline_math", "raw": body})
return m.end() | Parse older TeX-style inline math. | parse_inline_math_tex | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def parse_inline_math_latex(self, m: Match[str], state: InlineState) -> int:
"""Parse newer LaTeX-style inline math."""
body = m.group("math_inline_latex")
state.append_token({"type": "inline_math", "raw": body})
return m.end() | Parse newer LaTeX-style inline math. | parse_inline_math_latex | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def image(self, text: str, url: str, title: Optional[str] = None) -> str:
"""Rendering a image with title and text.
:param text: alt text of the image.
:param url: source link of the image.
:param title: title text of the image.
:note: The parameters `text` and `url` are swappe... | Rendering a image with title and text.
:param text: alt text of the image.
:param url: source link of the image.
:param title: title text of the image.
:note: The parameters `text` and `url` are swapped in older versions
of mistune.
| image | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def _embed_image_or_attachment(self, src: str) -> str:
"""Embed an image or attachment, depending on the configuration.
If neither is possible, returns the original URL.
"""
attachment_prefix = "attachment:"
if src.startswith(attachment_prefix):
name = src[len(attach... | Embed an image or attachment, depending on the configuration.
If neither is possible, returns the original URL.
| _embed_image_or_attachment | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def _src_to_base64(self, src: str) -> Optional[str]:
"""Turn the source file into a base64 url.
:param src: source link of the file.
:return: the base64 url or None if the file was not found.
"""
src_path = os.path.join(self.path, src)
if not os.path.exists(src_path):
... | Turn the source file into a base64 url.
:param src: source link of the file.
:return: the base64 url or None if the file was not found.
| _src_to_base64 | python | jupyter/nbconvert | nbconvert/filters/markdown_mistune.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/markdown_mistune.py | BSD-3-Clause |
def get_metadata(output, key, mimetype=None):
"""Resolve an output metadata key
If mimetype given, resolve at mimetype level first,
then fallback to top-level.
Otherwise, just resolve at top-level.
Returns None if no data found.
"""
md = output.get("metadata") or {}
if mimetype and mime... | Resolve an output metadata key
If mimetype given, resolve at mimetype level first,
then fallback to top-level.
Otherwise, just resolve at top-level.
Returns None if no data found.
| get_metadata | python | jupyter/nbconvert | nbconvert/filters/metadata.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/metadata.py | BSD-3-Clause |
def wrap_text(text, width=100):
"""
Intelligently wrap text.
Wrap text without breaking words if possible.
Parameters
----------
text : str
Text to wrap.
width : int, optional
Number of characters to wrap to, default 100.
"""
split_text = text.split("\n")
wrp = ... |
Intelligently wrap text.
Wrap text without breaking words if possible.
Parameters
----------
text : str
Text to wrap.
width : int, optional
Number of characters to wrap to, default 100.
| wrap_text | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def html2text(element):
"""extract inner text from html
Analog of jQuery's $(element).text()
"""
if isinstance(element, (str,)):
try:
element = ElementTree.fromstring(element)
except Exception:
# failed to parse, just return it unmodified
return eleme... | extract inner text from html
Analog of jQuery's $(element).text()
| html2text | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def _convert_header_id(header_contents):
"""Convert header contents to valid id value. Takes string as input, returns string.
Note: this may be subject to change in the case of changes to how we wish to generate ids.
For use on markdown headings.
"""
# Valid IDs need to be non-empty and contain no... | Convert header contents to valid id value. Takes string as input, returns string.
Note: this may be subject to change in the case of changes to how we wish to generate ids.
For use on markdown headings.
| _convert_header_id | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def strip_files_prefix(text):
"""
Fix all fake URLs that start with ``files/``, stripping out the ``files/`` prefix.
Applies to both urls (for html) and relative paths (for markdown paths).
Parameters
----------
text : str
Text in which to replace 'src="files/real...' with 'src="real...... |
Fix all fake URLs that start with ``files/``, stripping out the ``files/`` prefix.
Applies to both urls (for html) and relative paths (for markdown paths).
Parameters
----------
text : str
Text in which to replace 'src="files/real...' with 'src="real...'
| strip_files_prefix | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def comment_lines(text, prefix="# "):
"""
Build a Python comment line from input text.
Parameters
----------
text : str
Text to comment out.
prefix : str
Character to append to the start of each line.
"""
# Replace line breaks with line breaks and comment symbols.
#... |
Build a Python comment line from input text.
Parameters
----------
text : str
Text to comment out.
prefix : str
Character to append to the start of each line.
| comment_lines | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def get_lines(text, start=None, end=None):
"""
Split the input text into separate lines and then return the
lines that the caller is interested in.
Parameters
----------
text : str
Text to parse lines from.
start : int, optional
First line to grab from.
end : int, option... |
Split the input text into separate lines and then return the
lines that the caller is interested in.
Parameters
----------
text : str
Text to parse lines from.
start : int, optional
First line to grab from.
end : int, optional
Last line to grab from.
| get_lines | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def ipython2python(code):
"""Transform IPython syntax to pure Python syntax
Parameters
----------
code : str
IPython code, to be transformed to pure Python
"""
try:
from IPython.core.inputtransformer2 import TransformerManager
except ImportError:
warnings.warn(
... | Transform IPython syntax to pure Python syntax
Parameters
----------
code : str
IPython code, to be transformed to pure Python
| ipython2python | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def posix_path(path):
"""Turn a path into posix-style path/to/etc
Mainly for use in latex on Windows,
where native Windows paths are not allowed.
"""
if os.path.sep != "/":
return path.replace(os.path.sep, "/")
return path | Turn a path into posix-style path/to/etc
Mainly for use in latex on Windows,
where native Windows paths are not allowed.
| posix_path | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def prevent_list_blocks(s):
"""
Prevent presence of enumerate or itemize blocks in latex headings cells
"""
out = re.sub(r"(^\s*\d*)\.", r"\1\.", s)
out = re.sub(r"(^\s*)\-", r"\1\-", out)
out = re.sub(r"(^\s*)\+", r"\1\+", out)
out = re.sub(r"(^\s*)\*", r"\1\*", out)
return out # noqa:... |
Prevent presence of enumerate or itemize blocks in latex headings cells
| prevent_list_blocks | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def strip_trailing_newline(text):
"""
Strips a newline from the end of text.
"""
if text.endswith("\n"):
text = text[:-1]
return text |
Strips a newline from the end of text.
| strip_trailing_newline | python | jupyter/nbconvert | nbconvert/filters/strings.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/filters/strings.py | BSD-3-Clause |
def postprocess(self, input):
"""Serve the build directory with a webserver."""
dirname, filename = os.path.split(input)
handlers: list[tuple[t.Any, ...]] = [
(r"/(.+)", web.StaticFileHandler, {"path": dirname}),
(r"/", web.RedirectHandler, {"url": "/%s" % filename}),
... | Serve the build directory with a webserver. | postprocess | python | jupyter/nbconvert | nbconvert/postprocessors/serve.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/postprocessors/serve.py | BSD-3-Clause |
def preprocess(self, nb, resources):
"""
Preprocessing to apply on each notebook.
Must return modified nb, resources.
If you wish to apply your preprocessing to each cell, you might want
to override preprocess_cell method instead.
Parameters
----------
... |
Preprocessing to apply on each notebook.
Must return modified nb, resources.
If you wish to apply your preprocessing to each cell, you might want
to override preprocess_cell method instead.
Parameters
----------
nb : NotebookNode
Notebook being con... | preprocess | python | jupyter/nbconvert | nbconvert/preprocessors/base.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/base.py | BSD-3-Clause |
def current_key(self, mask_key):
"""Get the current key for a mask key."""
if isinstance(mask_key, str):
return mask_key
if len(mask_key) == 0:
# Safeguard
return None
return mask_key[0] | Get the current key for a mask key. | current_key | python | jupyter/nbconvert | nbconvert/preprocessors/clearmetadata.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/clearmetadata.py | BSD-3-Clause |
def nested_masks(self, mask):
"""Get the nested masks for a mask."""
return {
self.current_key(k[0]): k[1:]
for k in mask
if k and not isinstance(k, str) and len(k) > 1
} | Get the nested masks for a mask. | nested_masks | python | jupyter/nbconvert | nbconvert/preprocessors/clearmetadata.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/clearmetadata.py | BSD-3-Clause |
def nested_filter(self, items, mask):
"""Get the nested filter for items given a mask."""
keep_current = self.current_mask(mask)
keep_nested_lookup = self.nested_masks(mask)
for k, v in items:
keep_nested = keep_nested_lookup.get(k)
if k in keep_current:
... | Get the nested filter for items given a mask. | nested_filter | python | jupyter/nbconvert | nbconvert/preprocessors/clearmetadata.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/clearmetadata.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, cell_index):
"""
All the code cells are returned with an empty metadata field.
"""
if self.clear_cell_metadata and cell.cell_type == "code": # noqa: SIM102
# Remove metadata
if "metadata" in cell:
cell.me... |
All the code cells are returned with an empty metadata field.
| preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/clearmetadata.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/clearmetadata.py | BSD-3-Clause |
def preprocess(self, nb, resources):
"""
Preprocessing to apply on each notebook.
Must return modified nb, resources.
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the... |
Preprocessing to apply on each notebook.
Must return modified nb, resources.
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the conversion process. Allows
preproc... | preprocess | python | jupyter/nbconvert | nbconvert/preprocessors/clearmetadata.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/clearmetadata.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, cell_index):
"""
Apply a transformation on each cell. See base.py for details.
"""
if cell.cell_type == "code":
cell.outputs = []
cell.execution_count = None
# Remove metadata associated with output
... |
Apply a transformation on each cell. See base.py for details.
| preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/clearoutput.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/clearoutput.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, cell_index):
"""
Apply a transformation on each cell,
See base.py
"""
# Loop through all of the datatypes of the outputs in the cell.
for output in cell.get("outputs", []):
if (
output.output_type in... |
Apply a transformation on each cell,
See base.py
| preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/convertfigures.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/convertfigures.py | BSD-3-Clause |
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
... | 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
resource... | preprocess | python | jupyter/nbconvert | nbconvert/preprocessors/csshtmlheader.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/csshtmlheader.py | BSD-3-Clause |
def _generate_header(self, resources):
"""
Fills self.header with lines of CSS extracted from IPython
and Pygments.
"""
from pygments.formatters import HtmlFormatter
header = []
formatter = HtmlFormatter(style=self.style)
pygments_css = formatter.get_sty... |
Fills self.header with lines of CSS extracted from IPython
and Pygments.
| _generate_header | python | jupyter/nbconvert | nbconvert/preprocessors/csshtmlheader.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/csshtmlheader.py | BSD-3-Clause |
def preprocess(
self, nb: NotebookNode, resources: t.Any = None, km: KernelManager | None = None
) -> tuple[NotebookNode, dict[str, t.Any]]:
"""
Preprocess notebook executing each code cell.
The input argument *nb* is modified in-place.
Note that this function recalls Noteb... |
Preprocess notebook executing each code cell.
The input argument *nb* is modified in-place.
Note that this function recalls NotebookClient.__init__, which may look wrong.
However since the preprocess call acts line an init on execution state it's expected.
Therefore, we need t... | preprocess | python | jupyter/nbconvert | nbconvert/preprocessors/execute.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/execute.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, index):
"""
Override if you want to apply some preprocessing to each cell.
Must return modified cell and resource dictionary.
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resou... |
Override if you want to apply some preprocessing to each cell.
Must return modified cell and resource dictionary.
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the... | preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/execute.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/execute.py | BSD-3-Clause |
def preprocess(self, nb, resources):
"""
Determine some settings and apply preprocessor to notebook
"""
if self.use_separate_dir:
self.path_name = self.attachments_directory_template.format(
notebook_name=resources["unique_key"]
)
# Ini... |
Determine some settings and apply preprocessor to notebook
| preprocess | python | jupyter/nbconvert | nbconvert/preprocessors/extractattachments.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/extractattachments.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, index):
"""
Extract attachments to individual files and
change references to them.
E.g.
''
becomes
''
Assumes self.path_name and self.reso... |
Extract attachments to individual files and
change references to them.
E.g.
''
becomes
''
Assumes self.path_name and self.resources_item_key is set properly (usually in preprocess).
... | preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/extractattachments.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/extractattachments.py | BSD-3-Clause |
def guess_extension_without_jpe(mimetype):
"""
This function fixes a problem with '.jpe' extensions
of jpeg images which are then not recognised by latex.
For any other case, the function works in the same way
as mimetypes.guess_extension
"""
ext = guess_extension(mimetype)
if ext == ".j... |
This function fixes a problem with '.jpe' extensions
of jpeg images which are then not recognised by latex.
For any other case, the function works in the same way
as mimetypes.guess_extension
| guess_extension_without_jpe | python | jupyter/nbconvert | nbconvert/preprocessors/extractoutput.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/extractoutput.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, cell_index):
"""
Apply a transformation on each cell,
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion proces... |
Apply a transformation on each cell,
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jin... | preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/extractoutput.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/extractoutput.py | BSD-3-Clause |
def which_magic_language(self, source):
"""
When a cell uses another language through a magic extension,
the other language is returned.
If no language magic is detected, this function returns None.
Parameters
----------
source: str
Source code of the... |
When a cell uses another language through a magic extension,
the other language is returned.
If no language magic is detected, this function returns None.
Parameters
----------
source: str
Source code of the cell to highlight
| which_magic_language | python | jupyter/nbconvert | nbconvert/preprocessors/highlightmagics.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/highlightmagics.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, cell_index):
"""
Tags cells using a magic extension language
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion... |
Tags cells using a magic extension language
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into ... | preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/highlightmagics.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/highlightmagics.py | BSD-3-Clause |
def preprocess(self, nb, resources):
"""Preprocessing to apply on each notebook.
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors... | Preprocessing to apply on each notebook.
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jinja engine.
... | preprocess | python | jupyter/nbconvert | nbconvert/preprocessors/latex.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/latex.py | BSD-3-Clause |
def check_conditions(self, cell):
"""
Checks that a cell matches the pattern.
Returns: Boolean.
True means cell should *not* be removed.
"""
# Compile all the patterns into one: each pattern is first wrapped
# by a non-capturing group to ensure the correct order... |
Checks that a cell matches the pattern.
Returns: Boolean.
True means cell should *not* be removed.
| check_conditions | python | jupyter/nbconvert | nbconvert/preprocessors/regexremove.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/regexremove.py | BSD-3-Clause |
def preprocess(self, nb, resources):
"""
Preprocessing to apply to each notebook. See base.py for details.
"""
# Skip preprocessing if the list of patterns is empty
if not self.patterns:
return nb, resources
# Filter out cells that meet the conditions
... |
Preprocessing to apply to each notebook. See base.py for details.
| preprocess | python | jupyter/nbconvert | nbconvert/preprocessors/regexremove.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/regexremove.py | BSD-3-Clause |
def preprocess_cell(self, cell, resources, cell_index):
"""
Sanitize potentially-dangerous contents of the cell.
Cell Types:
raw:
Sanitize literal HTML
markdown:
Sanitize literal HTML
code:
Sanitize outputs that could result in c... |
Sanitize potentially-dangerous contents of the cell.
Cell Types:
raw:
Sanitize literal HTML
markdown:
Sanitize literal HTML
code:
Sanitize outputs that could result in code execution
| preprocess_cell | python | jupyter/nbconvert | nbconvert/preprocessors/sanitize.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/sanitize.py | BSD-3-Clause |
def sanitize_code_outputs(self, outputs):
"""
Sanitize code cell outputs.
Removes 'text/javascript' fields from display_data outputs, and
runs `sanitize_html_tags` over 'text/html'.
"""
for output in outputs:
# These are always ascii, so nothing to escape.
... |
Sanitize code cell outputs.
Removes 'text/javascript' fields from display_data outputs, and
runs `sanitize_html_tags` over 'text/html'.
| sanitize_code_outputs | python | jupyter/nbconvert | nbconvert/preprocessors/sanitize.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/sanitize.py | BSD-3-Clause |
def sanitize_html_tags(self, html_str):
"""
Sanitize a string containing raw HTML tags.
"""
kwargs = {
"tags": self.tags,
"attributes": self.attributes,
"strip": self.strip,
"strip_comments": self.strip_comments,
}
if _USE_... |
Sanitize a string containing raw HTML tags.
| sanitize_html_tags | python | jupyter/nbconvert | nbconvert/preprocessors/sanitize.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/sanitize.py | BSD-3-Clause |
def convert_figure(self, data_format, data):
"""
Convert a single SVG figure to PDF. Returns converted data.
"""
# Work in a temporary directory
with TemporaryDirectory() as tmpdir:
# Write fig to temp file
input_filename = os.path.join(tmpdir, "figure.s... |
Convert a single SVG figure to PDF. Returns converted data.
| convert_figure | python | jupyter/nbconvert | nbconvert/preprocessors/svg2pdf.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/svg2pdf.py | BSD-3-Clause |
def check_cell_conditions(self, cell, resources, index):
"""
Checks that a cell has a tag that is to be removed
Returns: Boolean.
True means cell should *not* be removed.
"""
# Return true if any of the tags in the cell are removable.
return not self.remove_cell... |
Checks that a cell has a tag that is to be removed
Returns: Boolean.
True means cell should *not* be removed.
| check_cell_conditions | python | jupyter/nbconvert | nbconvert/preprocessors/tagremove.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/tagremove.py | BSD-3-Clause |
def check_output_conditions(self, output, resources, cell_index, output_index):
"""
Checks that an output has a tag that indicates removal.
Returns: Boolean.
True means output should *not* be removed.
"""
return not self.remove_single_output_tags.intersection(
... |
Checks that an output has a tag that indicates removal.
Returns: Boolean.
True means output should *not* be removed.
| check_output_conditions | python | jupyter/nbconvert | nbconvert/preprocessors/tagremove.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/tagremove.py | BSD-3-Clause |
def unicode_stdin_stream():
"""Get a wrapper to read unicode from stdin as UTF-8.
This ignores environment variables and default encodings, to reliably read unicode from stdin.
::
totreat = unicode_stdin_stream().read()
"""
stream = sys.stdin
try:
stream_b = stream.buffer
... | Get a wrapper to read unicode from stdin as UTF-8.
This ignores environment variables and default encodings, to reliably read unicode from stdin.
::
totreat = unicode_stdin_stream().read()
| unicode_stdin_stream | python | jupyter/nbconvert | nbconvert/utils/io.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/io.py | BSD-3-Clause |
def link(src, dst):
"""Hard links ``src`` to ``dst``, returning 0 or errno.
Note that the special errno ``ENOLINK`` will be returned if ``os.link`` isn't
supported by the operating system.
"""
if not hasattr(os, "link"):
return ENOLINK
link_errno = 0
try:
os.link(src, dst)
... | Hard links ``src`` to ``dst``, returning 0 or errno.
Note that the special errno ``ENOLINK`` will be returned if ``os.link`` isn't
supported by the operating system.
| link | python | jupyter/nbconvert | nbconvert/utils/io.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/io.py | BSD-3-Clause |
def link_or_copy(src, dst):
"""Attempts to hardlink ``src`` to ``dst``, copying if the link fails.
Attempts to maintain the semantics of ``shutil.copy``.
Because ``os.link`` does not overwrite files, a unique temporary file
will be used if the target already exists, then that file will be moved
in... | Attempts to hardlink ``src`` to ``dst``, copying if the link fails.
Attempts to maintain the semantics of ``shutil.copy``.
Because ``os.link`` does not overwrite files, a unique temporary file
will be used if the target already exists, then that file will be moved
into place.
| link_or_copy | python | jupyter/nbconvert | nbconvert/utils/io.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/io.py | BSD-3-Clause |
def pandoc(source, fmt, to, extra_args=None, encoding="utf-8"):
"""Convert an input string using pandoc.
Pandoc converts an input string `from` a format `to` a target format.
Parameters
----------
source : string
Input string, assumed to be valid format `from`.
fmt : string
The... | Convert an input string using pandoc.
Pandoc converts an input string `from` a format `to` a target format.
Parameters
----------
source : string
Input string, assumed to be valid format `from`.
fmt : string
The name of the input format (markdown, etc.)
to : string
The ... | pandoc | python | jupyter/nbconvert | nbconvert/utils/pandoc.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/pandoc.py | BSD-3-Clause |
def get_pandoc_version():
"""Gets the Pandoc version if Pandoc is installed.
If the minimal version is not met, it will probe Pandoc for its version, cache it and return that value.
If the minimal version is met, it will return the cached version and stop probing Pandoc
(unless `clean_cache()` is calle... | Gets the Pandoc version if Pandoc is installed.
If the minimal version is not met, it will probe Pandoc for its version, cache it and return that value.
If the minimal version is met, it will return the cached version and stop probing Pandoc
(unless `clean_cache()` is called).
Raises
------
Pa... | get_pandoc_version | python | jupyter/nbconvert | nbconvert/utils/pandoc.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/pandoc.py | BSD-3-Clause |
def check_pandoc_version():
"""Returns True if pandoc's version meets at least minimal version.
Raises
------
PandocMissing
If pandoc is unavailable.
"""
if check_pandoc_version._cached is not None: # type:ignore[attr-defined]
return check_pandoc_version._cached # type:ignore[... | Returns True if pandoc's version meets at least minimal version.
Raises
------
PandocMissing
If pandoc is unavailable.
| check_pandoc_version | python | jupyter/nbconvert | nbconvert/utils/pandoc.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/pandoc.py | BSD-3-Clause |
def indent(instr, nspaces=4, ntabs=0, flatten=False):
"""Indent a string a given number of spaces or tabstops.
indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
Parameters
----------
instr : basestring
The string to be indented.
nspaces : int (default: 4)
The numbe... | Indent a string a given number of spaces or tabstops.
indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.
Parameters
----------
instr : basestring
The string to be indented.
nspaces : int (default: 4)
The number of spaces to be indented.
ntabs : int (default: 0)
... | indent | python | jupyter/nbconvert | nbconvert/utils/text.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/text.py | BSD-3-Clause |
def check_version(v, min_v, max_v=None):
"""check version string v >= min_v and v < max_v
Parameters
----------
v : str
version of the package
min_v : str
minimal version supported
max_v : str
earliest version not supported
Note: If dev/prerelease tags result in Type... | check version string v >= min_v and v < max_v
Parameters
----------
v : str
version of the package
min_v : str
minimal version supported
max_v : str
earliest version not supported
Note: If dev/prerelease tags result in TypeError for string-number
comparison, it is as... | check_version | python | jupyter/nbconvert | nbconvert/utils/version.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/utils/version.py | BSD-3-Clause |
def write(self, output, resources, notebook_name="notebook", **kw):
"""
Consume and write Jinja output.
See base for more...
"""
if isinstance(resources["outputs"], dict):
print("outputs extracted from %s" % notebook_name)
print("-" * 80)
ppr... |
Consume and write Jinja output.
See base for more...
| write | python | jupyter/nbconvert | nbconvert/writers/debug.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/writers/debug.py | BSD-3-Clause |
def _makedir(self, path, mode=0o755):
"""ensure that a directory exists
If it doesn't exist, try to create it and protect against a race condition
if another process is doing the same.
The default permissions are 755, which differ from os.makedirs default of 777.
"""
if... | ensure that a directory exists
If it doesn't exist, try to create it and protect against a race condition
if another process is doing the same.
The default permissions are 755, which differ from os.makedirs default of 777.
| _makedir | python | jupyter/nbconvert | nbconvert/writers/files.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/writers/files.py | BSD-3-Clause |
def _write_items(self, items, build_dir):
"""Write a dict containing filename->binary data"""
for filename, data in items:
# Determine where to write the file to
dest = os.path.join(build_dir, filename)
path = os.path.dirname(dest)
self._makedir(path)
... | Write a dict containing filename->binary data | _write_items | python | jupyter/nbconvert | nbconvert/writers/files.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/writers/files.py | BSD-3-Clause |
def write(self, output, resources, notebook_name=None, **kw):
"""
Consume and write Jinja output to the file system. Output directory
is set via the 'build_directory' variable of this instance (a
configurable).
See base for more...
"""
# Verify that a notebook ... |
Consume and write Jinja output to the file system. Output directory
is set via the 'build_directory' variable of this instance (a
configurable).
See base for more...
| write | python | jupyter/nbconvert | nbconvert/writers/files.py | https://github.com/jupyter/nbconvert/blob/master/nbconvert/writers/files.py | BSD-3-Clause |
def fuzzy_compare(
self,
a,
b,
newlines_are_spaces=True,
tabs_are_spaces=True,
fuzzy_spacing=True,
ignore_spaces=False,
ignore_newlines=False,
case_sensitive=False,
leave_padding=False,
):
"""
Performs a fuzzy comparison... |
Performs a fuzzy comparison of two strings. A fuzzy comparison is a
comparison that ignores insignificant differences in the two comparands.
The significance of certain differences can be specified via the keyword
parameters of this method.
| fuzzy_compare | python | jupyter/nbconvert | tests/base.py | https://github.com/jupyter/nbconvert/blob/master/tests/base.py | BSD-3-Clause |
def recursive_replace(self, text, search, replacement):
"""
Performs a recursive replacement operation. Replaces all instances
of a search string in a text string with a replacement string until
the search string no longer exists. Recursion is needed because the
replacement str... |
Performs a recursive replacement operation. Replaces all instances
of a search string in a text string with a replacement string until
the search string no longer exists. Recursion is needed because the
replacement string may generate additional search strings.
For example:
... | recursive_replace | python | jupyter/nbconvert | tests/base.py | https://github.com/jupyter/nbconvert/blob/master/tests/base.py | BSD-3-Clause |
def copy_files_to(self, copy_filenames, dest="."):
"""Copy test files into the destination directory"""
if not os.path.isdir(dest):
os.makedirs(dest)
files_path = self._get_files_path()
for pattern in copy_filenames:
files = glob.glob(os.path.join(files_path, patt... | Copy test files into the destination directory | copy_files_to | python | jupyter/nbconvert | tests/base.py | https://github.com/jupyter/nbconvert/blob/master/tests/base.py | BSD-3-Clause |
def nbconvert(self, parameters, ignore_return_code=False, stdin=None):
"""
Run nbconvert as a shell command, listening for both Errors and
non-zero return codes. Returns the tuple (stdout, stderr) of
output produced during the nbconvert run.
Parameters
----------
... |
Run nbconvert as a shell command, listening for both Errors and
non-zero return codes. Returns the tuple (stdout, stderr) of
output produced during the nbconvert run.
Parameters
----------
parameters : str, list(str)
List of parameters to pass to IPython.
... | nbconvert | python | jupyter/nbconvert | tests/base.py | https://github.com/jupyter/nbconvert/blob/master/tests/base.py | BSD-3-Clause |
def assert_big_text_equal(a, b, chunk_size=80):
"""assert that large strings are equal
Zooms in on first chunk that differs,
to give better info than vanilla assertEqual for large text blobs.
"""
for i in range(0, len(a), chunk_size):
chunk_a = a[i : i + chunk_size]
chunk_b = b[i : ... | assert that large strings are equal
Zooms in on first chunk that differs,
to give better info than vanilla assertEqual for large text blobs.
| assert_big_text_equal | python | jupyter/nbconvert | tests/base.py | https://github.com/jupyter/nbconvert/blob/master/tests/base.py | BSD-3-Clause |
def onlyif_cmds_exist(*commands):
"""
Decorator to skip test when at least one of `commands` is not found.
"""
for cmd in commands:
if not which(cmd):
return pytest.mark.skip(f"This test runs only if command '{cmd}' is installed")
return lambda f: f |
Decorator to skip test when at least one of `commands` is not found.
| onlyif_cmds_exist | python | jupyter/nbconvert | tests/testutils.py | https://github.com/jupyter/nbconvert/blob/master/tests/testutils.py | BSD-3-Clause |
def test_notebook_help(self):
"""Will help show if no notebooks are specified?"""
with self.create_temp_cwd():
out, err = self.nbconvert("--log-level 0", ignore_return_code=True)
self.assertIn("--help-all", out) | Will help show if no notebooks are specified? | test_notebook_help | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_glob(self):
"""
Do search patterns work for notebook names?
"""
with self.create_temp_cwd(["notebook*.ipynb"]):
self.nbconvert("--to python *.ipynb --log-level 0")
assert os.path.isfile("notebook1.py")
assert os.path.isfile("notebook2.py") |
Do search patterns work for notebook names?
| test_glob | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_glob_subdir(self):
"""
Do search patterns work for subdirectory notebook names?
"""
with self.create_temp_cwd():
self.copy_files_to(["notebook*.ipynb"], "subdir/")
self.nbconvert("--to python --log-level 0 " + os.path.join("subdir", "*.ipynb"))
... |
Do search patterns work for subdirectory notebook names?
| test_glob_subdir | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_convert_full_qualified_name(self):
"""
Test that nbconvert can convert file using a full qualified name for a
package, import and use it.
"""
with self.create_temp_cwd():
self.copy_files_to(["notebook*.ipynb"], "subdir")
self.copy_files_to(["../fa... |
Test that nbconvert can convert file using a full qualified name for a
package, import and use it.
| test_convert_full_qualified_name | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_absolute_template_file(self):
"""--template-file '/path/to/template.tpl'"""
with self.create_temp_cwd(["notebook*.ipynb"]), TemporaryDirectory() as td:
template = os.path.join(td, "mytemplate.tpl")
test_output = "success!"
with open(template, "w") as f:
... | --template-file '/path/to/template.tpl' | test_absolute_template_file | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_relative_template_file(self):
"""Test --template-file 'relative/path.tpl'"""
with self.create_temp_cwd(["notebook*.ipynb"]):
os.mkdir("relative")
template = os.path.join("relative", "path.tpl")
test_output = "success!"
with open(template, "w") as ... | Test --template-file 'relative/path.tpl' | test_relative_template_file | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_filename_spaces(self):
"""
Generate PDFs with graphics if notebooks have spaces in the name?
"""
with self.create_temp_cwd(["notebook2.ipynb"]):
os.rename("notebook2.ipynb", "notebook with spaces.ipynb")
self.nbconvert(
"--log-level 0 --to... |
Generate PDFs with graphics if notebooks have spaces in the name?
| test_filename_spaces | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_webpdf_with_chromium(self):
"""
Generate PDFs if chromium allowed to be downloaded?
"""
with self.create_temp_cwd(["notebook2.ipynb"]):
self.nbconvert('--to webpdf --allow-chromium-download "notebook2"')
assert os.path.isfile("notebook2.pdf") |
Generate PDFs if chromium allowed to be downloaded?
| test_webpdf_with_chromium | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_pdf(self):
"""
Check to see if pdfs compile, even if strikethroughs are included.
"""
with self.create_temp_cwd(["notebook2.ipynb"]):
self.nbconvert(
"--log-level 0 --to pdf"
' "notebook2"'
" --PDFExporter.latex_count=1... |
Check to see if pdfs compile, even if strikethroughs are included.
| test_pdf | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_png_base64_html_ok(self):
"""Is embedded png data well formed in HTML?"""
with self.create_temp_cwd(["notebook2.ipynb"]):
self.nbconvert("--log-level 0 --to HTML notebook2.ipynb --template lab")
assert os.path.isfile("notebook2.html")
with open("notebook2.htm... | Is embedded png data well formed in HTML? | test_png_base64_html_ok | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_glob_explicit(self):
"""
Can a search pattern be used along with matching explicit notebook names?
"""
with self.create_temp_cwd(["notebook*.ipynb"]):
self.nbconvert("--log-level 0 --to python *.ipynb notebook1.ipynb notebook2.ipynb")
assert os.path.isfil... |
Can a search pattern be used along with matching explicit notebook names?
| test_glob_explicit | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_explicit_glob(self):
"""
Can explicit notebook names be used and then a matching search pattern?
"""
with self.create_temp_cwd(["notebook*.ipynb"]):
self.nbconvert("--log-level 0 --to=python notebook1.ipynb notebook2.ipynb *.ipynb")
assert os.path.isfile(... |
Can explicit notebook names be used and then a matching search pattern?
| test_explicit_glob | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_override_config(self):
"""
Can the default config be overridden?
"""
with self.create_temp_cwd(
["notebook*.ipynb", "jupyter_nbconvert_config.py", "override.py"]
):
self.nbconvert('--log-level 0 --config="override.py"')
assert not os.p... |
Can the default config be overridden?
| test_override_config | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_cwd_plugin(self):
"""
Verify that an extension in the cwd can be imported.
"""
with self.create_temp_cwd(["hello.py"]):
self.create_empty_notebook("empty.ipynb")
assert os.path.isfile("hello.py")
self.nbconvert("empty --to html --NbConvertApp.... |
Verify that an extension in the cwd can be imported.
| test_cwd_plugin | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_output_suffix(self):
"""
Verify that the output suffix is applied
"""
with self.create_temp_cwd():
self.create_empty_notebook("empty.ipynb")
self.nbconvert("empty.ipynb --to notebook")
assert os.path.isfile("empty.nbconvert.ipynb") |
Verify that the output suffix is applied
| test_output_suffix | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_different_build_dir(self):
"""
Verify that the output suffix is not applied
"""
with self.create_temp_cwd():
self.create_empty_notebook("empty.ipynb")
os.mkdir("output")
self.nbconvert("empty.ipynb --to notebook --FilesWriter.build_directory=o... |
Verify that the output suffix is not applied
| test_different_build_dir | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_inplace(self):
"""
Verify that the notebook is converted in place
"""
with self.create_temp_cwd():
self.create_empty_notebook("empty.ipynb")
self.nbconvert("empty.ipynb --inplace")
assert os.path.isfile("empty.ipynb")
assert not os... |
Verify that the notebook is converted in place
| test_inplace | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_no_prompt(self):
"""
Verify that the html has no prompts when given --no-prompt.
"""
with self.create_temp_cwd(["notebook1.ipynb"]):
self.nbconvert("notebook1.ipynb --log-level 0 --no-prompt --to html")
assert os.path.isfile("notebook1.html")
... |
Verify that the html has no prompts when given --no-prompt.
| test_no_prompt | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_cell_tag_output(self):
"""
Verify that the html has tags in cell attributes if they exist.
"""
with self.create_temp_cwd(["notebook_tags.ipynb"]):
self.nbconvert("notebook_tags.ipynb --log-level 0 --to html")
assert os.path.isfile("notebook_tags.html")
... |
Verify that the html has tags in cell attributes if they exist.
| test_cell_tag_output | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_no_input(self):
"""
Verify that the html has no input when given --no-input.
"""
input_content_html = (
'<span class="n">x</span>'
'<span class="p">,</span> '
'<span class="n">y</span>'
'<span class="p">,</span> '
'<spa... |
Verify that the html has no input when given --no-input.
| test_no_input | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_allow_errors(self):
"""
Verify that conversion is aborted with '--execute' if an error is
encountered, but that conversion continues if '--allow-errors' is
used in addition.
"""
with self.create_temp_cwd(["notebook3*.ipynb"]):
# Convert notebook conta... |
Verify that conversion is aborted with '--execute' if an error is
encountered, but that conversion continues if '--allow-errors' is
used in addition.
| test_allow_errors | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
def test_errors_print_traceback(self):
"""
Verify that the stderr output contains the traceback of the cell execution exception.
"""
with self.create_temp_cwd(["notebook3_with_errors.ipynb"]):
_, error_output = self.nbconvert(
"--execute --to markdown --stdout... |
Verify that the stderr output contains the traceback of the cell execution exception.
| test_errors_print_traceback | python | jupyter/nbconvert | tests/test_nbconvertapp.py | https://github.com/jupyter/nbconvert/blob/master/tests/test_nbconvertapp.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.