Commit dece66c32a

dece66c32a50c8dc3f1134f9d32696f5c45192c7

parent: f9aa552633

Unsigned

cmc <hello@cleberg.net> · 2026-08-28 19:28 UTC

Render Org READMEs with the shared OrgSwift package

Depend on OrgSwift (ssh://git@gitbay.org/krz/org-swift.git) and render the .org
README path through OrgRenderer instead of the in-file org renderer. SyntaxHighlighter
conforms to OrgSwift.CodeHighlighter so code blocks keep their Highlightr highlighting;
the sr.ht relative-link resolution is passed through OrgRenderOptions.

Layout: unified · split

Hutch.xcodeproj/project.pbxproj +17
@@ -23,6 +23,7 @@
2323 8BE082012F80000100000001 /* HutchWidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 8BE081F62F80000100000001 /* HutchWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2424 8BE083012F81000100000001 /* HutchSafariExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 8BE083032F81000100000001 /* HutchSafariExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2525 8BF100032F9A000100000001 /* Markdown in Frameworks */ = {isa = PBXBuildFile; productRef = 8BF100022F9A000100000001 /* Markdown */; };
26 0F0F0F0F0F0F0F0F000000A3 /* OrgSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 0F0F0F0F0F0F0F0F000000A2 /* OrgSwift */; };
2627/* End PBXBuildFile section */
2728
2829/* Begin PBXContainerItemProxy section */
@@ -174,6 +175,7 @@
174175 files = (
175176 8BF100032F9A000100000001 /* Markdown in Frameworks */,
176177 8BAA000000000000000000B0 /* Highlightr in Frameworks */,
178 0F0F0F0F0F0F0F0F000000A3 /* OrgSwift in Frameworks */,
177179 );
178180 runOnlyForDeploymentPostprocessing = 0;
179181 };
@@ -325,6 +327,7 @@
325327 packageProductDependencies = (
326328 8BF100022F9A000100000001 /* Markdown */,
327329 8BAA000000000000000000B2 /* Highlightr */,
330 0F0F0F0F0F0F0F0F000000A2 /* OrgSwift */,
328331 );
329332 productName = Hutch;
330333 productReference = 8B4B28D12F6704280045FA19 /* Hutch.app */;
@@ -426,6 +429,7 @@
426429 packageReferences = (
427430 8BF100012F9A000100000001 /* XCRemoteSwiftPackageReference "swift-markdown" */,
428431 8BAA000000000000000000B3 /* XCRemoteSwiftPackageReference "Highlightr" */,
432 0F0F0F0F0F0F0F0F000000A1 /* XCRemoteSwiftPackageReference "org-swift" */,
429433 );
430434 preferredProjectObjectVersion = 77;
431435 productRefGroup = 8B4B28D22F6704280045FA19 /* Products */;
@@ -1019,6 +1023,14 @@
10191023 minimumVersion = 0.8.0;
10201024 };
10211025 };
1026 0F0F0F0F0F0F0F0F000000A1 /* XCRemoteSwiftPackageReference "org-swift" */ = {
1027 isa = XCRemoteSwiftPackageReference;
1028 repositoryURL = "ssh://git@gitbay.org/krz/org-swift.git";
1029 requirement = {
1030 branch = main;
1031 kind = branch;
1032 };
1033 };
10221034/* End XCRemoteSwiftPackageReference section */
10231035
10241036/* Begin XCSwiftPackageProductDependency section */
@@ -1032,6 +1044,11 @@
10321044 package = 8BF100012F9A000100000001 /* XCRemoteSwiftPackageReference "swift-markdown" */;
10331045 productName = Markdown;
10341046 };
1047 0F0F0F0F0F0F0F0F000000A2 /* OrgSwift */ = {
1048 isa = XCSwiftPackageProductDependency;
1049 package = 0F0F0F0F0F0F0F0F000000A1 /* XCRemoteSwiftPackageReference "org-swift" */;
1050 productName = OrgSwift;
1051 };
10351052/* End XCSwiftPackageProductDependency section */
10361053 };
10371054 rootObject = 8B4B28C92F6704280045FA19 /* Project object */;
Hutch.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +10 −1
@@ -1,5 +1,5 @@
11{
2 "originHash" : "4554417ca2693020116bce7cbda415a5e51ada6b4cc4a8b39f7f43a9644bb5e5",
2 "originHash" : "161ab13c39311c33c8ab987c4e00f5238e1b905e4b929b88f0ff7103a6dc20e4",
33 "pins" : [
44 {
55 "identity" : "highlightr",
@@ -10,6 +10,15 @@
1010 "version" : "2.3.0"
1111 }
1212 },
13 {
14 "identity" : "org-swift",
15 "kind" : "remoteSourceControl",
16 "location" : "ssh://git@gitbay.org/krz/org-swift.git",
17 "state" : {
18 "branch" : "main",
19 "revision" : "47ac630c479b79dbfa8944c91b22b7bb6974cadc"
20 }
21 },
1322 {
1423 "identity" : "swift-cmark",
1524 "kind" : "remoteSourceControl",
Hutch/Views/Repositories/ReadmeView.swift +12 −21
@@ -1,3 +1,4 @@
1import OrgSwift
12import SwiftUI
23import WebKit
34
@@ -314,29 +315,19 @@ struct RenderedMarkupContentView: View {
314315 return
315316 }
316317 let theme = SyntaxHighlightTheme(colorScheme: colorScheme)
318 let host = repositoryHost
319 let owner = ownerCanonicalName
320 let repo = repositoryName
321 let path = readmePath
317322 let html = await Task.detached(priority: .userInitiated) {
318 orgToHTML(
319 text,
320 codeTheme: theme,
321 imageURLResolver: { source in
322 resolveRepositoryAssetURL(
323 source,
324 owner: ownerCanonicalName,
325 repositoryName: repositoryName,
326 readmePath: readmePath
327 )?
328 .replacingOccurrences(of: "git.sr.ht", with: repositoryHost)
329 },
330 linkURLResolver: { source in
331 resolveRepositoryLinkURL(
332 source,
333 owner: ownerCanonicalName,
334 repositoryName: repositoryName,
335 readmePath: readmePath
336 )?
337 .replacingOccurrences(of: "git.sr.ht", with: repositoryHost)
338 }
323 let options = OrgRenderOptions(
324 host: host,
325 owner: owner,
326 repositoryName: repo,
327 ref: "HEAD",
328 readmePath: path
339329 )
330 return OrgRenderer.renderToHTML(text, options: options, highlighter: SyntaxHighlighter(theme: theme))
340331 }.value
341332 RenderedReadmeHTMLCache.shared.setHTML(html, forKey: cacheKey)
342333 guard !Task.isCancelled else { return }
Hutch/Views/Repositories/SyntaxHighlighter.swift +7 −1
@@ -1,5 +1,6 @@
11import Foundation
22import Highlightr
3import OrgSwift
34import SwiftUI
45import UIKit
56
@@ -31,7 +32,7 @@ nonisolated enum SyntaxHighlightTheme {
3132/// instance must stay on the thread/task that created it. Callers that fail to
3233/// resolve a language — or hit an unavailable engine — get `nil` and should
3334/// fall back to plain, escaped text.
34nonisolated final class SyntaxHighlighter {
35nonisolated final class SyntaxHighlighter: CodeHighlighter {
3536 private let highlightr: Highlightr?
3637 private let supportedLanguages: Set<String>
3738
@@ -60,6 +61,11 @@ nonisolated final class SyntaxHighlighter {
6061 return Self.html(from: attributed)
6162 }
6263
64 /// `OrgSwift.CodeHighlighter` conformance — delegates to the existing method.
65 func highlightedHTML(code: String, language: String?) -> String? {
66 highlightedHTML(for: code, language: language)
67 }
68
6369 private static let htmlMeasurementFont = UIFont.monospacedSystemFont(ofSize: 12, weight: .regular)
6470
6571 private func resolvedLanguage(_ raw: String?) -> String? {