feat: add JSON and YAML viewing with syntax highlighting - #45
Open
lpichler wants to merge 1 commit into
Open
Conversation
Wrap JSON/YAML file content in Markdown code fences so the existing marked.js + highlight.js pipeline renders them with syntax coloring. Register both file types with macOS Launch Services as Alternate viewers so the app appears in "Open With" without claiming ownership. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
.json,.yaml, and.ymlfiles with syntax highlightingHow it works
When a JSON or YAML file is opened,
HTMLRenderer.wrapForRendering(_:fileExtension:)wraps the raw text in a fenced code block (```jsonor```yaml). The existing rendering pipeline handles the rest — marked.js parses the code fence, highlight.js applies syntax coloring, and DOMPurify sanitizes the output.The wrapping only affects the rendering path. Raw operations (Copy Source, TOC parsing, review notes, file watching) continue to use the original file content unchanged.
Changes
MarkdownDocument.swift.jsonand.yamltoreadableContentTypesHTMLRenderer.swiftwrapForRendering(_:fileExtension:)— wraps JSON/YAML in code fences, passes other types throughContentView.swiftmarkdownForRendering(delegates toHTMLRenderer) for theMarkdownWebViewinputInfo.plistpublic.json) and YAML (public.yaml) document types withLSHandlerRank: AlternateDataFileRenderingTests.swiftDesign decisions
LSHandlerRank: Alternate(notOwner) — the app offers to view JSON/YAML without claiming to be the default handler, unlike Markdown where it's the primary viewer.JSON,.Yaml,.YMLetc.HTMLRenderer— the wrapping logic is a public static method, making it testable independently of SwiftUI viewsTest plan
.jsonfile → should render with syntax highlighting (colored keys, strings, numbers).yamlfile → should render with syntax highlighting.ymlfile → same as.yaml.mdfile → unchanged behavior, no code fence wrapping.jsonin Finder → "Open With" shows Markdown Viewer🤖 Generated with Claude Code