Repository navigation
refactor(format): add a document format registry with capabilities - #58
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
whenis that mapping, and the same answer kept twice is an answer that drifts. The registry is thatwhenrather 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.