Transforms

The transform system provides a powerful pipeline for modifying documents during conversion. Transforms operate on the AST (Abstract Syntax Tree) and can add, remove, or modify nodes.

Using Transforms

Transforms can be applied during conversion by passing them to the main API functions:

from all2md import to_markdown
from all2md.transforms import RemoveImagesTransform, HeadingOffsetTransform

markdown = to_markdown(
    'document.pdf',
    transforms=[
        RemoveImagesTransform(),
        HeadingOffsetTransform(offset=1)
    ]
)

Transforms can also be specified by name:

markdown = to_markdown('document.pdf', transforms=['remove-images', 'heading-offset'])

Transform Pipeline

The transform pipeline coordinates transform execution and rendering:

all2md.transforms.pipeline.Pipeline

Pipeline for transforming and rendering AST documents.

all2md.transforms.pipeline.render

Render document with transforms and hooks using specified renderer.

all2md.transforms.pipeline.apply

Apply transforms and hooks to document without rendering.

Transform Registry

The registry manages transform discovery and instantiation. Custom transforms can be registered via Python entry points:

all2md.transforms.registry.TransformRegistry

Registry for managing AST transforms.

Built-in Transforms

Commonly used transforms included with all2md:

all2md.transforms.builtin.RemoveImagesTransform

Remove all Image nodes from the AST.

all2md.transforms.builtin.RemoveNodesTransform

Remove nodes of specified types from the AST.

all2md.transforms.builtin.HeadingOffsetTransform

Shift heading levels by a specified offset.

all2md.transforms.builtin.TitlePromotionTransform

Promote a leading H1 to a document title and shift subsequent headings.

all2md.transforms.builtin.GenerateTocTransform

Generate a table of contents from document headings.

all2md.transforms.builtin.RemoveBoilerplateTextTransform

Remove paragraphs matching common boilerplate patterns.

all2md.transforms.builtin.AddAttachmentFootnotesTransform

Add footnote definitions for attachment references.

all2md.transforms.builtin.AddHeadingIdsTransform

Generate and add unique IDs to heading nodes.

all2md.transforms.builtin.LinkRewriterTransform

Rewrite link URLs using regex pattern matching.

all2md.transforms.builtin.TextReplacerTransform

Find and replace text in Text nodes.

all2md.transforms.builtin.AddConversionTimestampTransform

Add conversion timestamp to document metadata.

all2md.transforms.builtin.CalculateWordCountTransform

Calculate word and character counts and add to metadata.

For the complete list, see all2md.transforms.builtin.

Transform Hooks

Hooks allow custom code execution at specific points in the pipeline:

all2md.transforms.hooks.HookManager

Manager for registering and executing hooks.

all2md.transforms.hooks.HookContext

Context passed to hook functions.

Transform Options

Options for configuring transform behavior:

all2md.transforms.options.RemoveNodesOptions

Options for RemoveNodesTransform.

all2md.transforms.options.HeadingOffsetOptions

Options for HeadingOffsetTransform.

all2md.transforms.options.GenerateTocOptions

Options for GenerateTocTransform.

Complete Transform Reference