all2md.parsers.docx

DOCX to AST converter.

This module provides conversion from Microsoft Word DOCX documents to AST representation. It replaces direct markdown string generation with structured AST building, enabling multiple rendering strategies and improved testability.

class all2md.parsers.docx.ImageData

Bases: object

Structured representation of image data from DOCX.

Parameters:
  • url (str) – Image URL or data URI

  • alt_text (str) – Alternative text for the image

  • title (str or None) – Optional title for the image

  • footnote_label (str or None) – Footnote label if using footnote mode

  • footnote_content (str or None) – Footnote content text

  • source_data (str or None) – Source of the image data (e.g., “base64”, “downloaded”)

url: str
alt_text: str
title: str | None = None
footnote_label: str | None = None
footnote_content: str | None = None
source_data: str | None = None
__init__(url: str, alt_text: str, title: str | None = None, footnote_label: str | None = None, footnote_content: str | None = None, source_data: str | None = None) None
class all2md.parsers.docx.CommentData

Bases: object

Comment data from DOCX document.

Parameters:
  • identifier (str) – Comment ID

  • label (str) – Comment label/number

  • author (str) – Comment author name

  • date (str) – Comment date

  • text (str) – Comment text content

identifier: str
label: str
author: str
date: str
text: str
__init__(identifier: str, label: str, author: str, date: str, text: str) None
class all2md.parsers.docx.DocxToAstConverter

Bases: BaseParser

Convert DOCX to AST representation.

This converter parses Word documents using python-docx and builds an AST that can be rendered to various markdown flavors.

Parameters:
  • options (DocxOptions or None, default = None) – Conversion options

  • doc (docx.document.Document or None) – Document to convert (stored for list detection)

  • base_filename (str) – Base filename for image attachments

  • attachment_sequencer (callable or None) – Sequencer for generating attachment filenames

Initialize the DOCX parser with options and progress callback.

__init__(options: DocxOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)

Initialize the DOCX parser with options and progress callback.

options: DocxOptions
parse(input_data: str | Path | IO[bytes] | bytes) Document

Parse DOCX document into AST.

This method handles loading the DOCX file and converting it to AST. Performs security validation, dependency checking, and error handling.

Parameters:

input_data (str, Path, IO[bytes], or bytes) – DOCX file to parse

Returns:

AST document node

Return type:

Document

Raises:
extract_metadata(document: docx.document.Document) DocumentMetadata

Extract metadata from DOCX document.

Parameters:

document (docx.document.Document) – python-docx Document object

Returns:

Extracted metadata including title, author, dates, keywords, etc. Returns empty DocumentMetadata if no metadata is available.

Return type:

DocumentMetadata

Notes

Uses the OFFICE_FIELD_MAPPING to map core document properties to standard metadata fields. Also extracts DOCX-specific custom metadata properties such as last_modified_by, revision, version, and comments.

convert_to_ast(doc: docx.document.Document, base_filename: str = 'document') Document

Convert DOCX document to AST Document.

Parameters:
  • doc (docx.document.Document) – DOCX document to convert

  • base_filename (str, default="document") – Base filename for attachments

Returns:

AST document node

Return type:

Document