Sources/OrgSwiftUI/OrgCodeStyler.swift
20 lines · 814 bytes
4 symbols in this file
1import SwiftUI
2
3/// Syntax highlighting for `#+begin_src` blocks, supplied by the app.
4///
5/// The native counterpart to ``CodeHighlighter``: that one returns HTML for the HTML
6/// renderer, this returns an `AttributedString`. Keeping it a protocol is what lets
7/// OrgSwiftUI stay dependency-free — a highlighting engine is the app's business.
8///
9/// Returning nil means "show it as plain monospaced text", which is a fine outcome for an
10/// unknown language, never an error.
11@MainActor
12public protocol OrgCodeStyler {
13 func highlighted(code: String, language: String?) -> AttributedString?
14}
15
16/// The default: no highlighting.
17public struct PlainOrgCodeStyler: OrgCodeStyler {
18 nonisolated public init() {}
19 public func highlighted(code _: String, language _: String?) -> AttributedString? { nil }
20}