all2md.options.ipynb

Configuration options for Jupyter Notebook parsing.

This module defines options for parsing .ipynb files with cell handling.

class all2md.options.ipynb.IpynbOptions

Bases: BaseParserOptions, AttachmentOptionsMixin

Configuration options for IPYNB-to-Markdown conversion.

This dataclass contains settings specific to Jupyter Notebook processing, including output handling and image conversion preferences. Inherits attachment handling from AttachmentOptionsMixin for notebook output images.

Parameters:
  • include_inputs (bool, default True) – Whether to include cell input (source code) in output.

  • include_outputs (bool, default True) – Whether to include cell outputs in the markdown.

  • skip_empty_cells (bool, default True) – Whether to skip cells with no content. When False, empty cells are preserved as empty blocks to maintain round-trip fidelity. When True, empty cells are omitted for cleaner output.

  • show_execution_count (bool, default False) – Whether to show execution counts for code cells.

  • output_types (list[str] or None, default ["stream", "execute_result", "display_data"]) – Types of outputs to include. Valid types: “stream”, “execute_result”, “display_data”, “error”. If None, includes all output types.

  • truncate_long_outputs (int or None, default DEFAULT_TRUNCATE_OUTPUT_LINES) – Maximum number of lines for text outputs before truncating. If None, outputs are not truncated.

  • truncate_output_message (str or None, default DEFAULT_TRUNCATE_OUTPUT_MESSAGE) – The message to place to indicate truncated output.

  • strip_html_from_markdown (bool, default True) – Whether to strip HTML elements (HTMLInline and HTMLBlock nodes) from markdown cells for security. When True, HTML in markdown cells is removed to prevent XSS attacks. When False, HTML is preserved as-is (use only with trusted notebooks).

include_inputs: bool = True
include_outputs: bool = True
skip_empty_cells: bool = True
show_execution_count: bool = False
output_types: tuple[str, ...] | None = ('stream', 'execute_result', 'display_data')
truncate_long_outputs: int | None = None
truncate_output_message: str | None = '\n... (output truncated) ...\n'
strip_html_from_markdown: bool = True
__init__(attachment_mode: AttachmentMode = 'alt_text', alt_text_mode: AltTextMode = 'default', attachment_output_dir: str | None = None, attachment_base_url: str | None = None, max_asset_size_bytes: int = 52428800, attachment_filename_template: str = '{stem}_{type}{seq}.{ext}', attachment_overwrite: AttachmentOverwriteMode = 'unique', attachment_deduplicate_by_hash: bool = False, attachments_footnotes_section: str | None = 'Attachments', extract_metadata: bool = False, include_inputs: bool = True, include_outputs: bool = True, skip_empty_cells: bool = True, show_execution_count: bool = False, output_types: tuple[str, ...] | None = ('stream', 'execute_result', 'display_data'), truncate_long_outputs: int | None = None, truncate_output_message: str | None = '\n... (output truncated) ...\n', strip_html_from_markdown: bool = True) None
class all2md.options.ipynb.IpynbRendererOptions

Bases: BaseRendererOptions

Configuration options for rendering AST documents to Jupyter notebooks.

These options control notebook metadata inference, attachment handling, and preservation of notebook-specific metadata to support near round-tripping between AST and .ipynb formats.

Parameters:
  • nbformat (int or "auto", default 4) – Major notebook format version to emit. When “auto”, use the version discovered in the source document metadata and fall back to 4.

  • nbformat_minor (int or "auto", default "auto") – Minor notebook format revision. “auto” preserves the original value from document metadata when available.

  • default_language (str, default "python") – Fallback programming language when the document does not provide one.

  • default_kernel_name (str, default "python3") – Fallback kernel name for kernelspec metadata when inference fails.

  • default_kernel_display_name (str, default "Python 3") – Fallback kernel display name when inference fails.

  • infer_language_from_document (bool, default True) – When True, prefer Document.metadata[“language”] (and related fields) before default_language.

  • infer_kernel_from_document (bool, default True) – When True, attempt to build kernelspec metadata from document metadata (e.g., custom[“kernel”]) before falling back to defaults.

  • include_trusted_metadata (bool, default False) – When False, strip trusted flags from cell metadata for safer output.

  • include_ui_metadata (bool, default False) – When False, drop UI hints such as collapsed, scrolled, and widget metadata to avoid propagating viewer state.

  • preserve_unknown_metadata (bool, default True) – When True, retain metadata keys that are not explicitly filtered out.

  • inline_attachments (bool, default True) – Whether to emit attachments inline (base64-encoded) in the notebook instead of delegating to external download locations.

  • markdown_options (MarkdownRendererOptions or None, default None) – Optional Markdown renderer configuration used when consolidating AST nodes into markdown notebook cells. When None, a default renderer is constructed per cell.

nbformat: int | Literal['auto'] = 4
nbformat_minor: int | Literal['auto'] = 'auto'
default_language: str = 'python'
default_kernel_name: str = 'python3'
default_kernel_display_name: str = 'Python 3'
infer_language_from_document: bool = True
infer_kernel_from_document: bool = True
include_trusted_metadata: bool = False
include_ui_metadata: bool = False
preserve_unknown_metadata: bool = True
inline_attachments: bool = True
markdown_options: MarkdownRendererOptions | None = None
__init__(fail_on_resource_errors: bool = False, max_asset_size_bytes: int = 52428800, metadata_policy: MetadataRenderPolicy = <factory>, creator: str | None = 'all2md', nbformat: int | Literal['auto'] = 4, nbformat_minor: int | Literal['auto'] = 'auto', default_language: str = 'python', default_kernel_name: str = 'python3', default_kernel_display_name: str = 'Python 3', infer_language_from_document: bool = True, infer_kernel_from_document: bool = True, include_trusted_metadata: bool = False, include_ui_metadata: bool = False, preserve_unknown_metadata: bool = True, inline_attachments: bool = True, markdown_options: MarkdownRendererOptions | None = None) None