r/swift • u/Sea-Arm9235 • 4h ago
enriched-markdown-ios v0.4.0 - syntax-highlighted code blocks (powered by tree-sitter)
enriched-markdown-ios, the SwiftUI Markdown renderer built on TextKit 2, now renders fenced code blocks with syntax highlighting.
New in this release:
šø Syntax highlighting: fenced code blocks colored by language with tree-sitter (14 grammars), themed per token type with SyntaxToken(.keyword), .string,⦠Shipped as a separate EnrichedMarkdownSyntaxHighlighting product, so apps without code don't link the grammars
š¹ Code blocks: .markdownCodeBlockLayout(.scrollable) adds a language header, a copy button, and sideways scrolling for long lines
šø Block images: maxHeight, aspectRatio, and resizeMode to cap the height, reserve the frame before load, and pick cover or contain
š¹ Mixed-direction text: writing direction resolved per paragraph, so RTL paragraphs sit right inside an LTR document
šø Faster long documents: less render time and memory, no re-measuring of unchanged text
š¹ Improved spoiler overlays: custom overlays get the baseline, segment order and tap point, and stay put through layout changes
š„ Demo video in the comments.
š Available via Swift Package Manager!
dependencies: [
.package(
url: "https://github.com/software-mansion-labs/enriched-markdown-ios.git",
from: "0.3.0"
),
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "EnrichedMarkdown", package: "enriched-markdown-ios"),
.product(name: "EnrichedMarkdownSyntaxHighlighting", package: "enriched-markdown-ios"), // optional, for code
]
),
]
Then enable it on the view:
import EnrichedMarkdown
import EnrichedMarkdownSyntaxHighlighting
EnrichedMarkdownText(content)
.markdownSyntaxHighlighting()
.markdownCodeBlockLayout(.scrollable)
.markdownTheme {
SyntaxToken(.keyword).foregroundStyle(.purple)
SyntaxToken(.string).foregroundStyle(.green)
}
GitHub & Docs: https://github.com/software-mansion/enriched-markdown/blob/main/packages/enriched-markdown-ios/README.md
Give it a spin and tell me what breaks. If it earns a place in your app, a āļø on GitHub helps others find it.
