Skip to content

refactor(format): add a document format registry with capabilities - #58

Merged
usamaiqb merged 1 commit into
mainfrom
refactor/format-registry
Oct 17, 2026
Merged

usamaiqb merged 1 commit into
mainfrom
refactor/format-registry

Conversation

@usamaiqb

Copy link
Copy Markdown
Owner

A new com.markreader.format holds DocumentFormat, FormatCapabilities, RenderTheme, ReaderContent and a FormatRegistry keyed on DocumentType, with Markdown, source-code and plain-text formats under it. The Markwon and Prism4j renderers move out of ui/markdown/ to sit with the formats that own them.

The ten "is this Markdown" and "is this source code" tests in the viewer and the editor become capability reads, and isMarkdown leaves the codebase. Each format owns its renderer and its per-theme cache, so the editor preview and the viewer render through one Markwon configuration rather than two configured separately.

DocumentFormat carries no type. Nothing asks a format what it reads, the registry's when is that mapping, and the same answer kept twice is an answer that drifts. The registry is that when rather than the list first sketched: precedence existed for recognition, formats do not recognise anything, and a list would carry a meaningless ordering plus a scan. Exhaustiveness is what protects us instead — adding a document type now fails to compile until a format is chosen for it.

load() returns a nullable ReaderContent and renderFailureWarningRes is nullable as one decision: a format whose rendering is its source has nothing to fall back to and so no failure to describe. ReaderContent is defined here, with only Spans produced; the two places that narrow to it are what the reader surface's own retyping deletes.

One user-visible change. Where a format has no raw view the chrome names the format instead of a view mode, because "Rendered mode" is untrue of a document whose rendering is its source, so a .txt chip reads "Plain text". One layer down, ReaderContentView's isSourceCode is isMonospaced: the render layer keeps no opinion about what a document is, only about how to draw it.

Also fixes a stale-state bug. The failure path in loadUri never wrote documentType, so a binary file opened after a Markdown one still offered a table-of-contents button over empty headings.

The detekt baseline is not regenerated: two entries re-keyed for the isSourceCode rename, six deleted as dead.

A new com.markreader.format holds DocumentFormat, FormatCapabilities,
RenderTheme, ReaderContent and a FormatRegistry keyed on DocumentType, with
Markdown, source-code and plain-text formats under it. The Markwon and Prism4j
renderers move out of ui/markdown/ to sit with the formats that own them.

The ten "is this Markdown" and "is this source code" tests in the viewer and the
editor become capability reads, and isMarkdown leaves the codebase. Each format
owns its renderer and its per-theme cache, so the editor preview and the viewer
render through one Markwon configuration rather than two configured separately.

DocumentFormat carries no type. Nothing asks a format what it reads, the
registry's `when` is that mapping, and the same answer kept twice is an answer
that drifts. The registry is that `when` rather than the list first sketched:
precedence existed for recognition, formats do not recognise anything, and a
list would carry a meaningless ordering plus a scan. Exhaustiveness is what
protects us instead — adding a document type now fails to compile until a format
is chosen for it.

load() returns a nullable ReaderContent and renderFailureWarningRes is nullable
as one decision: a format whose rendering is its source has nothing to fall back
to and so no failure to describe. ReaderContent is defined here, with only Spans
produced; the two places that narrow to it are what the reader surface's own
retyping deletes.

One user-visible change. Where a format has no raw view the chrome names the
format instead of a view mode, because "Rendered mode" is untrue of a document
whose rendering is its source, so a .txt chip reads "Plain text". One layer down,
ReaderContentView's isSourceCode is isMonospaced: the render layer keeps no
opinion about what a document is, only about how to draw it.

Also fixes a stale-state bug. The failure path in loadUri never wrote
documentType, so a binary file opened after a Markdown one still offered a
table-of-contents button over empty headings.

The detekt baseline is not regenerated: two entries re-keyed for the
isSourceCode rename, six deleted as dead.
@usamaiqb usamaiqb self-assigned this Oct 16, 2026
@usamaiqb
usamaiqb merged commit be22ac6 into main Oct 17, 2026
3 checks passed
@usamaiqb
usamaiqb deleted the refactor/format-registry branch October 17, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant