all2md.options.docx
Configuration options for DOCX parsing and rendering.
This module defines options for Microsoft Word document conversion, supporting both AST parsing and rendering operations.
- class all2md.options.docx.DocxRendererOptions
Bases:
BaseRendererOptionsConfiguration options for rendering AST to DOCX format.
This dataclass contains settings specific to Word document generation, including fonts, styles, and formatting preferences.
- Parameters:
default_font (str, default "Calibri") – Default font name for body text.
default_font_size (int, default 11) – Default font size in points for body text.
heading_font_sizes (dict[int, int] or None, default None) – Font sizes for heading levels 1-6. If None, uses built-in Word heading styles.
use_styles (bool, default True) – Whether to use built-in Word styles vs direct formatting.
table_style (str or None, default "Light Grid Accent 1") – Built-in table style name. If None, uses plain table formatting.
code_font (str, default "Courier New") – Font name for code blocks and inline code.
code_font_size (int, default 10) – Font size for code blocks and inline code.
preserve_formatting (bool, default True) – Whether to preserve text formatting (bold, italic, etc.).
template_path (str or None, default None) – Path to .docx template file. When specified, the renderer uses the template’s styles (headings, body text, etc.) instead of creating a blank document. This is powerful for corporate environments where documents must adopt specific style guidelines defined in a template.
network (NetworkFetchOptions, default NetworkFetchOptions()) – Network security settings for fetching remote images. By default, remote image fetching is disabled (allow_remote_fetch=False). Set network.allow_remote_fetch=True to enable secure remote image fetching with the same security guardrails as PPTX renderer.
comment_mode ({"native", "visible", "ignore"}, default "native") – How to render Comment and CommentInline AST nodes: - “native”: Use python-docx native comment API (preserves Word comments when possible) - “visible”: Render as regular text paragraphs with attribution - “ignore”: Skip comment nodes entirely This controls presentation of comments from DOCX source files and other formats.
promote_title (bool, default True) – When True, a leading H1 is rendered with Word’s “Title” style instead of “Heading 1”, and all subsequent headings are promoted by one level (H2 → Heading 1, H3 → Heading 2, etc.). Set to False to keep all H1s as “Heading 1”.
- default_font: str = 'Calibri'
- default_font_size: int = 11
- heading_font_sizes: dict[int, int] | None = None
- use_styles: bool = True
- table_style: str | None = 'Light Grid Accent 1'
- code_font: str = 'Courier New'
- code_font_size: int = 10
- preserve_formatting: bool = True
- template_path: str | None = None
- clear_template_body: bool = False
- comment_mode: Literal['native', 'visible', 'ignore'] = 'native'
- promote_title: bool = True
- network: NetworkFetchOptions
- __init__(fail_on_resource_errors: bool = False, max_asset_size_bytes: int = 52428800, metadata_policy: MetadataRenderPolicy = <factory>, creator: str | None = 'all2md', default_font: str = 'Calibri', default_font_size: int = 11, heading_font_sizes: dict[int, int] | None=None, use_styles: bool = True, table_style: str | None = 'Light Grid Accent 1', code_font: str = 'Courier New', code_font_size: int = 10, preserve_formatting: bool = True, template_path: str | None = None, clear_template_body: bool = False, comment_mode: Literal['native', 'visible', 'ignore']='native', promote_title: bool = True, network: NetworkFetchOptions = <factory>) None
- class all2md.options.docx.DocxOptions
Bases:
BaseParserOptions,AttachmentOptionsMixinConfiguration options for DOCX-to-Markdown conversion.
This dataclass contains settings specific to Word document processing, including image handling and formatting preferences. Inherits attachment handling from AttachmentOptionsMixin for embedded images and media.
- Parameters:
preserve_tables (bool, default True) – Whether to preserve table formatting in Markdown.
Examples
- Convert with base64 image embedding:
>>> options = DocxOptions(attachment_mode="base64")
- preserve_tables: bool = True
- include_footnotes: bool = True
- include_endnotes: bool = True
- include_comments: bool = False
- comments_position: Literal['inline', 'footnotes'] = 'footnotes'
- include_image_captions: bool = True
- code_style_names: list[str]
- code_char_style_names: list[str]
- quote_style_names: list[str]
- __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, preserve_tables: bool = True, include_footnotes: bool = True, include_endnotes: bool = True, include_comments: bool = False, comments_position: Literal['inline', 'footnotes']='footnotes', include_image_captions: bool = True, code_style_names: list[str] = <factory>, code_char_style_names: list[str] = <factory>, quote_style_names: list[str] = <factory>) None