Repository navigation
Move blob rendering behind a viewer registry - #16
Merged
Merged
Conversation
The blob page used to hardwire its file types: a closed enum in classifyBlob, a switch in handleBlob, and an if/else chain in the template. Adding a preview meant touching all three. Now server/viewer owns content rendering. Each file type is one Renderer behind a small Match/Render interface and the server walks an ordered registry: first match wins, a render error falls through to the next match, and the code viewer sits last so any text file still renders. Structural states (symlink, LFS, too big, empty) stay in the handler since they describe the record, not the content. The highlight, markdown and octicon code moves into the new package unchanged apart from exported names. The raw endpoint now serves through http.ServeContent with the shared MIME table, which buys Range and HEAD support for the media viewers coming next. The Preview/Code toggle is computed server side: on a plain view the registry is probed without the plain flag, so the toggle stays visible on files whose rich viewer stepped aside. Spec 2011 doc 18, PR 1 of 4.
This was referenced Jun 11, 2026
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.
The blob page hardwired its file types in three places: the classifyBlob enum, the handleBlob switch, and an if/else chain in blob.tmpl. Every new preview meant touching all three.
This introduces server/viewer, an ordered registry of small Match/Render renderers. The server walks it, first match wins, and a render error degrades to the next match instead of failing the page. The code viewer matches every non-binary file and sits last, so text always renders. Structural blob states (symlink, LFS pointer, too big, empty) stay in the handler: they are states of the record, not content.
What moved, what changed:
No new file types in this PR. Spec 2011 doc 18, PR 1 of 4: media, tabular (csv/tsv/parquet) and docx viewers follow.