HTMLEditor-SwiftUI is a macOS Swift package that provides a SwiftUI HTML editor with syntax highlighting, theme support, and an adaptive large-document runtime designed to keep typing and scrolling responsive.
- macOS 13+
- Swift 6 toolchain
- Compatible with Swift 6.3
- SwiftUI
HTMLEditorbacked by AppKit for macOS editing behavior. - HTML syntax highlighting for tags, attribute names, and attribute values.
- Custom light and dark themes with configurable fonts and colors.
- Adaptive highlighting pipeline:
- full semantic highlighting for smaller HTML documents
- viewport-first highlighting for large documents
- performance-oriented large-file mode for very large HTML inputs
- Large-document optimizations including:
- visible-range plan caching
- document-scoped invalidation
- structural dirty-range alignment
- burst-coalesced edit repainting
- scroll-idle semantic refresh
- automatic non-contiguous layout in large-file mode
- Benchmark target for repeatable performance measurements.
-
Open your project in Xcode.
-
Choose File > Add Packages...
-
Enter:
https://github.com/makoni/HTMLEditor-SwiftUI.git -
Add the library product HTMLEditor-SwiftUI.
-
Import the module in Swift code:
import HTMLEditor
.package(url: "https://github.com/makoni/HTMLEditor-SwiftUI.git", from: "1.1.0")import SwiftUI
import HTMLEditor
struct ContentView: View {
@State private var htmlContent = "<p>Hello, World!</p>"
var body: some View {
HTMLEditor(html: $htmlContent)
.frame(minWidth: 400, minHeight: 300)
.padding()
}
}import SwiftUI
import AppKit
import HTMLEditor
struct CustomThemeView: View {
@State private var htmlContent = "<p>Custom Theme Example</p>"
private let customTheme = HTMLEditorTheme(
light: HTMLEditorColorScheme(
foreground: .blue,
background: .yellow,
tag: .purple,
attributeName: .orange,
attributeValue: .green,
font: .monospacedSystemFont(ofSize: 16, weight: .bold)
),
dark: HTMLEditorColorScheme(
foreground: .white,
background: .black,
tag: .red,
attributeName: .cyan,
attributeValue: .magenta,
font: .monospacedSystemFont(ofSize: 16, weight: .bold)
)
)
var body: some View {
HTMLEditor(html: $htmlContent, theme: customTheme)
.frame(minWidth: 400, minHeight: 300)
.padding()
}
}The editor uses different runtime strategies depending on document size.
- Smaller documents use fuller semantic highlighting.
- Large documents switch to viewport-first highlighting and stronger cache reuse.
- Very large documents use a more conservative editing mode with localized repaint, delayed wider recovery, and scroll-idle semantic work to keep interaction responsive.
This means the editor is optimized for both short snippets and multi-megabyte HTML files, but the very-large-file mode intentionally prioritizes responsiveness over immediate full-detail recoloring.
The package includes an executable benchmark target:
swift run HTMLEditorBenchmarksTo benchmark a specific HTML file:
HTML_EDITOR_BENCHMARK_HTML=/path/to/file.html swift run HTMLEditorBenchmarksThe repository includes a demo app in HTMLEditorDemoApp/.
xcodebuild -project HTMLEditorDemoApp/HTMLEditor-Demo.xcodeproj \
-scheme HTMLEditor-Demo \
-destination 'platform=macOS' \
build CODE_SIGNING_ALLOWED=NOBuild the package:
swift buildRun tests:
swift testMIT. See LICENSE.
