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.xcodeproj/project.pbxproj | 17 +++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 11 ++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'Hutch.xcodeproj') diff --git a/Hutch.xcodeproj/project.pbxproj b/Hutch.xcodeproj/project.pbxproj index b7ddbe9..b6c7301 100644 --- a/Hutch.xcodeproj/project.pbxproj +++ b/Hutch.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 8B2FA9D12F7E211800E609E2 /* paste.json in Resources */ = {isa = PBXBuildFile; fileRef = 8B2FA9C92F7E211800E609E2 /* paste.json */; }; 8B2FA9D22F7E211800E609E2 /* todo.json in Resources */ = {isa = PBXBuildFile; fileRef = 8B2FA9CA2F7E211800E609E2 /* todo.json */; }; 8B2FA9D32F7E211800E609E2 /* lists.json in Resources */ = {isa = PBXBuildFile; fileRef = 8B2FA9C72F7E211800E609E2 /* lists.json */; }; + 8BAA000000000000000000B0 /* Highlightr in Frameworks */ = {isa = PBXBuildFile; productRef = 8BAA000000000000000000B2 /* Highlightr */; }; 8BE082012F80000100000001 /* HutchWidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 8BE081F62F80000100000001 /* HutchWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 8BE083012F81000100000001 /* HutchSafariExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 8BE083032F81000100000001 /* HutchSafariExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 8BF100032F9A000100000001 /* Markdown in Frameworks */ = {isa = PBXBuildFile; productRef = 8BF100022F9A000100000001 /* Markdown */; }; @@ -148,6 +149,7 @@ buildActionMask = 2147483647; files = ( 8BF100032F9A000100000001 /* Markdown in Frameworks */, + 8BAA000000000000000000B0 /* Highlightr in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -252,6 +254,7 @@ name = Hutch; packageProductDependencies = ( 8BF100022F9A000100000001 /* Markdown */, + 8BAA000000000000000000B2 /* Highlightr */, ); productName = Hutch; productReference = 8B4B28D12F6704280045FA19 /* Hutch.app */; @@ -358,6 +361,7 @@ minimizedProjectReferenceProxies = 1; packageReferences = ( 8BF100012F9A000100000001 /* XCRemoteSwiftPackageReference "swift-markdown" */, + 8BAA000000000000000000B3 /* XCRemoteSwiftPackageReference "Highlightr" */, ); preferredProjectObjectVersion = 77; productRefGroup = 8B4B28D22F6704280045FA19 /* Products */; @@ -871,6 +875,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 8BAA000000000000000000B3 /* XCRemoteSwiftPackageReference "Highlightr" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/raspu/Highlightr"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.1.0; + }; + }; 8BF100012F9A000100000001 /* XCRemoteSwiftPackageReference "swift-markdown" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/apple/swift-markdown"; @@ -882,6 +894,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 8BAA000000000000000000B2 /* Highlightr */ = { + isa = XCSwiftPackageProductDependency; + package = 8BAA000000000000000000B3 /* XCRemoteSwiftPackageReference "Highlightr" */; + productName = Highlightr; + }; 8BF100022F9A000100000001 /* Markdown */ = { isa = XCSwiftPackageProductDependency; package = 8BF100012F9A000100000001 /* XCRemoteSwiftPackageReference "swift-markdown" */; diff --git a/Hutch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Hutch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 417e4d7..a268436 100644 --- a/Hutch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Hutch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,6 +1,15 @@ { - "originHash" : "65542d8a5fbbad8dd7d07c8901c1cc48b3aba12cef8da1f062bd28d9b3a6ba50", + "originHash" : "4554417ca2693020116bce7cbda415a5e51ada6b4cc4a8b39f7f43a9644bb5e5", "pins" : [ + { + "identity" : "highlightr", + "kind" : "remoteSourceControl", + "location" : "https://github.com/raspu/Highlightr", + "state" : { + "revision" : "05e7fcc63b33925cd0c1faaa205cdd5681e7bbef", + "version" : "2.3.0" + } + }, { "identity" : "swift-cmark", "kind" : "remoteSourceControl", -- cgit v1.2.3