From b410fd16b76146f4116538c5b82330818dd47da9 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Fri, 7 Aug 2026 02:45:31 -0500 Subject: Add multi-language syntax highlighting (#16) Splash (Swift-only, since removed) left code rendering unhighlighted everywhere. Add Highlightr (highlight.js) behind a small SyntaxHighlighter service and use it on both surfaces: - Native file viewer: highlight NSAttributedString by language inferred from the filename, picking a light/dark theme from the trait style and re-highlighting on style changes. Falls back to plain text for unknown languages or very large files. - Markdown/org code blocks in the WKWebView (READMEs, tickets, comments): the web view disables JavaScript, so highlight server-side into inline color-styled spans. The color scheme is now part of the render/cache key since colors are baked into the HTML. Covered by unit tests for language mapping and highlighted output. --- Hutch/Views/Tickets/TicketDetailView.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Hutch/Views/Tickets') diff --git a/Hutch/Views/Tickets/TicketDetailView.swift b/Hutch/Views/Tickets/TicketDetailView.swift index 6339776..1ace6b6 100644 --- a/Hutch/Views/Tickets/TicketDetailView.swift +++ b/Hutch/Views/Tickets/TicketDetailView.swift @@ -553,14 +553,22 @@ private struct MarkdownContentView: View { .frame(minHeight: 80) } } - .task(id: markdown) { + .task(id: MarkdownRenderKey(markdown: markdown, isDark: colorScheme == .dark)) { + let theme = SyntaxHighlightTheme(colorScheme: colorScheme) let html = await Task.detached(priority: .userInitiated) { - markdownToHTML(markdown) + markdownToHTML(markdown, codeTheme: theme) }.value guard !Task.isCancelled else { return } renderedHTML = html } } + + /// Re-renders when the markdown or the color scheme changes; highlighted + /// code colors are baked into the HTML, so both must key the render. + private struct MarkdownRenderKey: Equatable { + let markdown: String + let isDark: Bool + } } // MARK: - Event Row -- cgit v1.2.3