Skip to content

Feat/extension seam - #100

Merged
luca-chen198 merged 4 commits into
mainfrom
feat/extension-seam
Jul 15, 2026
Merged

luca-chen198 merged 4 commits into
mainfrom
feat/extension-seam

Conversation

@luca-chen198

Copy link
Copy Markdown
Member

No description provided.

The engine grew a steady stream of non-CommonMark inline constructs
hard-wired into the parser, styler, tokenizer, and HTML renderer. Adding
one (`%%` comments, etc.) meant ~15 edits across ~9 files, and a bug in
one construct could hide in code shared with another.

This introduces an extension seam. A `MarkdownExtension` supplies only a
`SpanSyntax` (open/close delimiter pair + matching flags), content
attributes, and an HTML wrapper; register instances via
`MarkdownEditorConfiguration.extensions`. Extensions never emit ranges —
the parser derives all span geometry — so a misbehaving extension can at
worst restyle its own span, never a neighbor. Marker mute/shrink, caret
reveal, incremental restyle, table cells, and rich copy are handled
generically. All parse caches (block-token memo, document memo,
DocumentParseState, table-image cache) key on the registry fingerprint,
so registered extensions can change at runtime without stale results.

`==highlight==` and `~~strikethrough~~`, formerly built into the core
grammar, are now `HighlightExtension` / `StrikethroughExtension` in
Sources/MarkdownEngine/Extensions/ — the core parses pure markdown, and
unregistered syntax stays literal text. This is a breaking change:
register both to restore the previous behavior.

A golden corpus (one HTML-snapshot fixture per construct, baseline
recorded pre-seam) proves the extraction changed nothing — byte-identical
output with the extensions registered, literal `==`/`~~` without, every
other construct untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luca-chen198
luca-chen198 force-pushed the feat/extension-seam branch from 24e2358 to 358d84d Compare July 15, 2026 11:28
@luca-chen198 luca-chen198 linked an issue Jul 15, 2026 that may be closed by this pull request
luca-chen198 and others added 3 commits July 15, 2026 17:12
The extension seam is about constructs in general, not only inline spans —
the CONTRIBUTING constraint, README feature list, and CHANGELOG entry now
say 'construct' and leave the concrete form open (block support lands
next). Extensions get their own feature bullet in the README.

Also repairs the CHANGELOG: the rebase onto main had left the seam entries
inside 0.9.0 and pushed 0.9.0's own Added items under Changed; 0.9.0 is
byte-identical to main again and the seam entries sit under Unreleased.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Inline spans were only half the story: block-shaped constructs (callouts,
containers, admonitions) still required threading a new case through the
parser, styler, tokenizer, and renderer. This generalizes MarkdownExtension
to contribute an inline form, a fenced block form (BlockSyntax), or both.

A fenced extension block mirrors ``` semantics exactly: a line starting
with the fence opens it, the next fence line closes it, unclosed runs to
the end of the document. Built-ins always classify first, so an extension
can never take text away from core markdown. The incremental machinery is
fence-aware end to end: hasBlockDelimiter consults registered fences, the
splice window bails on trailing extension blocks, every parse cache keys
on the registry fingerprint, and an edit touching a fence line triggers
the full-document restyle the same way the backtick census does.

ContainerExtension (`::: … :::`) is the first block extension and the
contributor template; it is not registered by default.

The review pass on this change also surfaced and fixed a pre-existing
incremental-parse gap: backspace-joining two paragraphs could leave the
splice with two adjacent paragraph blocks where a full parse merges them,
causing transient styling divergence until the next edit. The trailing
guard now falls back to the full reparse in that case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luca-chen198
luca-chen198 marked this pull request as ready for review July 15, 2026 16:08
@luca-chen198
luca-chen198 merged commit e25e8f9 into main Jul 15, 2026
1 check passed
@xandaaaa
xandaaaa deleted the feat/extension-seam branch July 22, 2026 09:59
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.

Add extension for non markdown features

1 participant