Reference#
- class nbpreview.notebook.Notebook(notebook_node, theme='ansi_dark', plain=None, unicode=None, hide_output=False, nerd_font=False, files=True, negative_space=True, hyperlinks=None, hide_hyperlink_hints=False, images=None, image_drawing=None, color=None, relative_dir=None, line_numbers=False, code_wrap=False)#
Construct a Notebook object to render Jupyter Notebooks.
- Parameters
notebook_node (NotebookNode) – A NotebookNode of the notebook to render.
theme (str) – The theme to use for syntax highlighting. May be
'ansi_light'
,'ansi_dark'
, or any Pygments theme. By default'ansi_dark'
.plain (Optional[bool]) – Only show plain style. No decorations such as boxes or execution counts. If set to
None
will autodetect. By defaultNone
.unicode (Optional[bool]) – Whether to use unicode characters to render the notebook. If set to
None
will autodetect. By defaultNone
.hide_output (bool) – Do not render the notebook outputs. By default
False
.nerd_font (bool) – Use nerd fonts when appropriate. By default
False
.files (bool) – Create files when needed to render HTML content. By default
True
.negative_space (bool) – Whether render character images in negative space. By default
True
hyperlinks (Optional[bool]) – Whether to use hyperlinks. If
False
will explicitly print out path. If set toNone
will autodetect. By defaultNone
.hide_hyperlink_hints (bool) – Hide text hints of when content is clickable. By default
False
.images (Optional[bool]) – Whether to render images. If set to
None
will autodetect. By defaultNone
.image_drawing (Optional[Union[ImageDrawingEnum, Literal['block', 'character', 'braille']]]) – The characters used to render images. Options are
'block'
,'character'
,'braille'
orNone
. If set toNone
will autodetect. By defaultNone
.color (Optional[bool]) – Whether to use color. If set to
None
will autodetect. By defaultNone
.relative_dir (dataclasses.InitVar[Optional[pathlib.Path]]) – The directory to prefix relative paths to convert them to absolute. If
None
will assume current directory is relative prefix. By defaultNone
.line_numbers (bool) – Whether to render line numbers in code cells. By default
False
.code_wrap (bool) – Whether to wrap code if it does not fit. By default
False
.
- classmethod from_file(file, theme='ansi_dark', plain=None, unicode=None, hide_output=False, nerd_font=False, files=True, negative_space=True, hyperlinks=None, hide_hyperlink_hints=False, images=None, image_drawing=None, color=None, line_numbers=False, code_wrap=False)#
Create a Notebook from notebook file.
- Parameters
file (
Union
[Path
,IO
[AnyStr
],KeepOpenFile
]) – A path to a Jupyter Notebook file.theme (
str
) – The theme to use for syntax highlighting. May be'ansi_light'
,'ansi_dark'
, or any Pygments theme. By default'ansi_dark'
.plain (
Optional
[bool
]) – Only show plain style. No decorations such as boxes or execution counts. If set toNone
will autodetect. By defaultNone
.unicode (
Optional
[bool
]) – Whether to use unicode characters to render the notebook. If set toNone
will autodetect. By defaultNone
.hide_output (
bool
) – Do not render the notebook outputs. By defaultFalse
.nerd_font (
bool
) – Use nerd fonts when appropriate. By defaultFalse
.files (
bool
) – Create files when needed to render HTML content. By defaultTrue
.negative_space (
bool
) – Whether render character images in negative space. By defaultTrue
.hyperlinks (
Optional
[bool
]) – Whether to use hyperlinks. IfFalse
will explicitly print out path. If set toNone
will autodetect. By defaultNone
.hide_hyperlink_hints (
bool
) – Hide text hints of when content is clickable. By defaultFalse
.images (
Optional
[bool
]) – Whether to render images. If set toNone
will autodetect. By defaultNone
.image_drawing (
Union
[ImageDrawingEnum
,Literal
[‘block’, ‘character’, ‘braille’],None
]) – The characters used to render images. Options are'block'
,'character'
,'braille'
orNone
. If set toNone
will autodetect. By defaultNone
.color (
Optional
[bool
]) – Whether to use color. If set toNone
will autodetect. By defaultNone
.line_numbers (
bool
) – Whether to render line numbers in code cells. By defaultFalse
.code_wrap (
bool
) – Whether to wrap code if it does not fit. By defaultFalse
.
- Returns
A Notebook object created from the file.
- Return type
- Raises
InvalidNotebookError – If the file is not a valid Jupyter notebook.