import Foundation /// Resolves a link target or image source to a safe absolute URL string, or nil when it /// cannot be made safe. /// /// Because the tree keeps targets typed, resolution is a renderer concern applied to the /// `.file` case only — no resolver closure has to be threaded through the parse. Both /// renderers resolve identically, so a link that degrades to text in HTML degrades to text /// natively too. package struct OrgURLResolver: Sendable { package var options: OrgRenderOptions package init(options: OrgRenderOptions) { self.options = options } package func href(for target: OrgLinkTarget) -> String? { switch target { case .id(let identifier): return sanitizedReadmeLinkURLString("#\(identifier)") case .external(let url): return sanitizedReadmeLinkURLString(url) case .file(let path): return sanitizedReadmeLinkURLString(options.linkURLResolver()?(path) ?? path) } } package func imageSource(_ source: String) -> String? { sanitizedReadmeImageURLString(options.imageURLResolver()?(source) ?? source) } /// The text a target shows when it carries no description. package func displayValue(_ target: OrgLinkTarget) -> String { switch target { case .external(let url): return url case .file(let path): return path case .id(let identifier): return identifier } } }