Skip to content

feat: add an extensions mechanism - #504

Open
nlopes wants to merge 55 commits into
mainfrom
nlopes-extension-foundation
Open

nlopes wants to merge 55 commits into
mainfrom
nlopes-extension-foundation

Conversation

@nlopes

@nlopes nlopes commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Right now, the flow I'm thinking about is roughly the one per the mermaid diagram and taking into account all the types of extension types that asciidoctor supports, to the best of my knowledge and understanding.

Goal

The goal should be to be able to support implementing things like:

Types of extensions

Extension type acdc boundary
Preprocessor Source reader, before parsing
Include processor Reader encounters an include directive
Block processor A registered block style is recognized
Block macro processor A registered block macro is recognized
Tree processor Complete block tree, before conversion
Inline macro processor Inline substitution during conversion
Docinfo processor Backend header/footer insertion points
Postprocessor Completed output, before writing

Flow

flowchart TD
    subgraph setup["Pipeline setup — acdc-converters-core, called by CLI or library"]
        A[Select backend and extension registrations]
    end

    subgraph parser["Parser — acdc-parser"]
        B[Source reader and preprocessor hooks]
        C[Recognize and commit next block]
        D[Invoke block or block macro processor]
        E[Document under construction]
        F[Run tree processors through the document editor]
        G[Finalize affected document data under the numbering policy]
    end

    subgraph converter["Converters — acdc-converters-core and selected backend"]
        L[Resolve deferred labels through parser-owned builders]
        H[Convert with inline processors, render overrides, and docinfo hooks]
        I[Run output postprocessors]
    end

    A --> B
    B --> C
    C --> D
    D --> B
    C --> E
    D --> E
    E --> F
    F --> G
    G -->|Finalized structural data| L
    L --> H
    H --> I

    style setup fill:#fff4d6,stroke:#997000,color:#332600
    style parser fill:#e8f1ff,stroke:#2563eb,color:#102a56
    style converter fill:#e8f7ee,stroke:#23834b,color:#123b24
Loading

@nlopes
nlopes force-pushed the nlopes-extension-foundation branch 3 times, most recently from 209d1f5 to a2baa7f Compare November 15, 2026 18:51
Recognize opt-in block macros with the shared attribute parser and run fresh
processors after document acceptance. Retain source-position attributes,
deferred requests, typed queries, and collision-free target IDs.

Reject pending nodes at finalization and checked ASG export. Keep ordinary
parser entry points and inactive behavior unchanged. Callbacks cannot affect
later includes or conditionals.

Validation: 12,405 workspace tests and 117 doctests passed;
strict Clippy, formatting, feature-off parser/HTML checks, and whitespace checks
passed. 1 workspace test skipped; 5 doctests ignored.

Refs: SC-256
Run document-local tree processors in registration order through a scoped
editor. Build literal paragraphs and lists, insert content, replace pending
requests, and remove sections while preserving stable target handles.

Repair references, TOC membership, scoped footnotes, and diagnostics without
rerunning callbacks or renumbering surviving sections and captions. Cover
the public finalization and HTML conversion paths in both compatibility modes.

Validation: 12,416 workspace tests and 118 doctests passed;
strict Clippy, formatting, feature-off parser/HTML checks, and whitespace checks
passed. 1 workspace test skipped; 5 doctests ignored.

Refs: SC-256
Retain conditional and comment state between input advances and preserve include source maps and fast bulk reads.

Part of SC-535.
Reuse existing block rules through a top-level cursor and finalize the accepted tree outside the document grammar.

Part of SC-535. Nested source-order integration remains open.
Build section children, compound bodies, list attachments, quote bodies,
and AsciiDoc table cells after their recognizers return. Reuse the native
recognizers, metadata handling, and builders while retaining the ordinary
recursive parsing path. Keep handler failures fatal through content recovery
and preserve caption, footnote, attribute-scope, and diagnostic ordering.

The accepted-block execution boundary remains internal. Public registry
callbacks retain their existing post-document timing pending A2.

SC-535 remains In Progress: cooperative source integration and performance
acceptance follow in separate changes.

Validated checkpoint: 12,562 workspace tests, 118 doctests, strict workspace
Clippy, 1,221 feature-off tests, formatting, and diff checks. No existing
fixture expectations were changed.

Refs: SC-535
Connect the resumable preprocessor and ordered block cursor through a
private source-handler seam. Apply accepted attribute assignments before
advancing to later directives, while preserving include policies, source
origins, bounded cell scopes, and stable input storage.

Reuse the native grammar for source boundaries and preserve the recursive
ordinary parsing path. Keep window coordinates separate from local inline
maps and avoid repeated copies of the complete processed prefix. Retain
direct local location lookup for ordinary input.

Cover source order in nested lists and includes, failure stopping later
include reads, caller attribute locks, selected include source maps, and
compound/cell scope parity. Fix nested-list ID source locations.

Validation: 12,594 workspace tests, 118 doctests, 1,253 feature-off parser
tests, strict all-targets/all-features Clippy, formatting, and diff checks.
The four include benchmark workloads completed. Paired ordinary parsing
measurements still leave performance acceptance open; SC-535 remains In
Progress. Public Registry callback migration belongs to A2.

Refs SC-535.
Keep ordinary documents on the direct shared grammar and reuse unchanged
source storage in the ordered driver. Reduce deferred-block copies and
list allocations, and narrow the source-handler context to host-owned effects.

Preserve fatal source failures through nested-list recovery. Cover source
order, buffered input, attribute-driven styles, and retained source storage.

Refs SC-535.
Let the private source coordinator advance through compound bodies and
pipe/exclamation AsciiDoc cells at committed block boundaries. Reuse the
existing delimiters, table placement, attribute policy, and diagnostics.
Retain buffered handling for other table formats.
Run block macros as their blocks commit so callbacks can affect later
conditionals and includes. Keep mutable handlers and deferred requests
local to each document, with original source and attribute snapshots.

Cover compound bodies and AsciiDoc cells with regressions and fixtures.
Document buffered CSV/TSV behavior and effects that survive later errors.

Refs SC-536
Preserve raw title input, substitutions, source locations, and source-position attributes before inline interpretation. Expose them through BlockView::title_source() and retain the context across placeholder replacement without changing native serialization.

Refs SC-537.
Exercise generic query and ID consumers through paired fixtures. Cover depth-first traversal in supported containers, query observations after edits, foreign and removed handles, real ID collisions, and request-order determinism in both compatibility modes.

Refs SC-537.
Let tree processors generate image and verbatim output or replace retained source through parser builders. Normalize metadata in the target's source context while retaining its identity, title, and inherited attributes.

Validate and repair a candidate before publishing edits so a failed edit leaves the document and counters intact. Preserve surviving numbers, advance new captions beyond used ordinals and local numeric seeds, and expose idempotent normalization without callbacks.

Refs SC-538.
Exercise image and literal construction through paired parser fixtures with separate producer and query processors. Add an HTML diagram consumer using public handles and builders to verify inherited source context, captions, escaping, and cross references in both compatibility modes.

Refs SC-538.
Freeze selected titles and source context behind document-local target identities. Bind final captions and output IDs after edits, then let converter core request ordinary explicit cross-reference labels from parser-owned builders. Accept literal and structured list items through the same constructor.
Prepare generated display labels for each conversion across HTML, Markdown, terminal, manpage, and PDF output. Preserve frozen title formatting, resolve caption edits and renamed targets, and collect captured PDF title assets before rendering. Exercise the public extension API with shared fixtures and repeated-conversion regressions.
Select backend configuration and named registrations before source processing, then coordinate parser finalization and display preparation for library callers.

Add reader sessions and atomic registry composition while preserving the inactive parser path and structured diagnostics. Reset HTML index counters for each conversion so reused converters produce stable output.

SC-540
Select named extension packages explicitly and reject unavailable names before reading input. Route files, stdin, batches, terminal output, and pagers through the backend-aware library pipeline while preserving warning presentation and output options.

Use injected registrations for route and isolation tests, keeping the production catalog empty until an extension package is available.

SC-540
Combine parser and renderer registrations in explicit extension selections. Add backend-filtered factories, conversion-local sessions, and rendering host contracts.

Carry selected registrations through the generic converter pipeline and adapt CLI types while preserving existing rendering defaults.

SC-541
@nlopes
nlopes force-pushed the nlopes-extension-foundation branch from 4590e44 to 227dacc Compare November 18, 2026 17:22
@nlopes nlopes linked an issue Nov 19, 2026 that may be closed by this pull request
@nlopes
nlopes marked this pull request as ready for review November 22, 2026 11:12
nlopes and others added 27 commits November 22, 2026 20:21
Resolve each macro’s surviving requests in source order and reject edits to another macro’s pending placeholders. Migrate the lists and diagram handlers to the scoped registration.

Refs: SC-584
Use the buffered tag recognizer when an entire line is available and retain streaming recognition across decoder chunks. Exercise both paths through the existing include loader.

Refs: SC-546
Run registered preprocessors once on the normalized entry source. Compose edits in registration order, anchor generated lines at the authored position, and keep the borrowed input when there are no edits.

Refs: SC-546
Dispatch active include directives after target resolution and access checks. Pass supplied bytes through the existing include reader to preserve selection, limits, nested scopes, and source locations.

Refs: SC-546
Construct returned builders at the committed invocation and retain its title, metadata, and source span. Tree processors can query the ordinary block immediately. Keep the callback output usable by shared registry factories.

Refs: SC-547
Dispatch a document-local processor at the committed delimiter before body substitutions. Preserve raw text, title, source spans, and source-position arguments, and construct the returned block through the same host path as a block macro.

Refs: SC-547
Let a style hand its preprocessed body back to the document parser after its callback returns. Nested handlers share their document-local state and source locations. Limit active style requests and report excess nesting at the invocation.

Refs SC-547
Exercise paragraph source replacement through a registered tree processor in both compatibility modes. Check source-position attributes, warning repair, and exactly one style callback per document.

Refs SC-547
- key deferred out-of-sequence section warnings by the preprocessed heading
  offset, so they survive includes and conditionals
- apply a caller-supplied leveloffset in extension sessions
- match registered block macros like asciidoctor: no whitespace in the
  target and nothing but whitespace after the closing bracket
- drop an unquoted `None` macro argument only in Asciidoctor mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Recovery used to drop quote bodies, Markdown blockquotes, and list or
description-list attachments even when a block processor had already run
inside them. Its attribute changes and deferred requests outlived the
dropped blocks, so finish() or a tree processor failed at a location no
longer in the document, and list recovery could run a macro twice.

Report an extension error at the first such invocation instead. Content
without executed processors still recovers as before. Streamed compound
blocks get the same check, though no known input reaches that path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Display links copied the captured title or custom caption verbatim, so an
inline anchor registered twice and a footnote made preparation fail with
"belongs to multiple retained scopes". The copy now drops anchors,
footnotes, and concealed index terms, keeps only the text of visible index
terms, and clears span and link IDs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A style can warn at its invocation and still return fallback content or ask the parser to read its children. Preserve the original location through includes and expose the warning in the parse result.
Retain authored invocations in macro-enabled spans and resolve them after tree edits with the selected backend and source-position attributes. Give each conversion its own processors and counters, and reuse each result across copied labels.

Refs SC-549
@nlopes
nlopes force-pushed the nlopes-extension-foundation branch from 9a00611 to 6c80f1f Compare November 22, 2026 19:59
@nlopes nlopes changed the title Building an extensions mechanism - DO NOT USE YET feat: add an extensions mechanism Nov 22, 2026
Let renderers, docinfo hooks, and text postprocessors select a canonical backend family or a single variant. Preserve existing string registrations and include CSP hashes only for matching HTML renderers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add an extensions mechanism

1 participant