### Quick Start: Basic Editor View Setup Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/Sources/MarkdownEngine/MarkdownEngine.docc/MarkdownEngine.md This snippet shows how to integrate the NativeTextViewWrapper into a SwiftUI view to display and edit Markdown text. It initializes the text and state variables required for the editor. ```swift import SwiftUI import MarkdownEngine struct EditorScreen: View { @State private var text: String = "# Hello, *world*" @State private var isLinkActive: Bool = false @State private var pendingReplacement: InlineReplacementRequest? var body: some View { NativeTextViewWrapper( text: $text, isWikiLinkActive: $isLinkActive, pendingInlineReplacement: $pendingReplacement, configuration: .default, fontName: "SF Pro", documentId: "doc-1" ) } } ``` -------------------------------- ### Commit Message Example Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/CONTRIBUTING.md Example of a commit message following the recommended format: imperative subject, blank line, and explanatory paragraph. ```git Tokenize escaped backticks inside fenced code blocks The previous tokenizer treated `\`` inside ``` … ``` as a token delimiter, which broke any code block containing escaped backtick examples. The new behavior matches CommonMark. ``` -------------------------------- ### Implementing a Custom WikiLinkResolver Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Provide a custom implementation for resolving wiki links. This example shows how to define a struct conforming to `WikiLinkResolver` and integrate it into the editor's services configuration. ```swift struct MyResolver: WikiLinkResolver { func resolve(displayName: String, range: NSRange) -> WikiLinkResolution? { myIndex[displayName].map { WikiLinkResolution(id: $0, exists: true) } } } configuration.services = MarkdownEditorServices( wikiLinks: MyResolver() // images, syntaxHighlighter, latex omitted → no-op defaults ) ``` -------------------------------- ### Swift Package Manager Installation Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Add the Swift Markdown Engine to your project's dependencies using Swift Package Manager. This snippet shows the necessary configuration for your Package.swift file. ```swift dependencies: [ .package(url: "https://github.com/nodes-app/swift-markdown-engine", from: "0.1.0") ], targets: [ .target( name: "YourApp", dependencies: [ .product(name: "MarkdownEngine", package: "swift-markdown-engine"), ] ) ] ``` -------------------------------- ### Basic Markdown Editor Setup in SwiftUI Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Integrate a basic Markdown editor into your SwiftUI view. This snippet shows the essential import statements and how to declare a state variable for the text content. ```swift import SwiftUI import MarkdownEngine struct EditorScreen: View { @State private var text: String = "# Hello, *world*" var body: some View { NativeTextViewWrapper(text: $text) } } ``` -------------------------------- ### Clone and Build Project Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/CONTRIBUTING.md Steps to clone the repository, build the project, and run tests. ```bash git clone https://github.com/nodes-app/swift-markdown-engine.git cd swift-markdown-engine swift build swift test ``` -------------------------------- ### Wiring Up Custom Services for MarkdownEngine Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/Sources/MarkdownEngine/MarkdownEngine.docc/MarkdownEngine.md Shows how to provide custom implementations for various Markdown features like wiki-links, image handling, syntax highlighting, and LaTeX rendering. These services are injected into the editor's configuration. ```swift let services = MarkdownEditorServices( wikiLinks: MyWikiLinkResolver(), images: MyImageProvider(), syntaxHighlighter: MySyntaxHighlighter(), latex: MyLatexRenderer() ) var configuration = MarkdownEditorConfiguration.default configuration.services = services ``` -------------------------------- ### Preview Documentation Locally Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/CONTRIBUTING.md Command to preview the DocC documentation locally using the swift package manager. ```bash swift package --disable-sandbox preview-documentation --target MarkdownEngine ``` -------------------------------- ### Configuring Syntax Highlighting with HighlighterSwiftBridge Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Set up syntax highlighting for code blocks using the recommended `HighlighterSwiftBridge`. This requires importing `MarkdownEngineCodeBlocks` and passing an instance of the bridge to the editor's services. ```swift import MarkdownEngineCodeBlocks var configuration = MarkdownEditorConfiguration.default configuration.services = MarkdownEditorServices( syntaxHighlighter: HighlighterSwiftBridge() ) ``` -------------------------------- ### Configuring LaTeX Rendering with SwiftMathBridge Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Enable LaTeX rendering by configuring the editor's services with `SwiftMathBridge`. This requires importing `MarkdownEngineLatex` and provides a robust solution for rendering mathematical formulas. ```swift import MarkdownEngineLatex var configuration = MarkdownEditorConfiguration.default configuration.services = MarkdownEditorServices( latex: SwiftMathBridge() ) ``` -------------------------------- ### Add DocC Plugin for Local Preview Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/CONTRIBUTING.md Temporarily add the swift-docc plugin to Package.swift to preview documentation locally. ```swift .package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.4.0") ``` -------------------------------- ### Source Layout - MarkdownEngine Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/ARCHITECTURE.md Defines the directory structure for the core MarkdownEngine target, detailing subdirectories for configuration, services, parsing, styling, rendering, input handling, and the native text view implementation. ```bash Sources/ ├── MarkdownEngine/ # core target — zero deps │ ├── Configuration/ # MarkdownEditorConfiguration + MarkdownEditorTheme │ ├── Services/ # 4 protocols, no-op defaults, WikiLinkService │ ├── Parser/ # two-phase AST: BlockParser → InlineParser → DocumentAST (+ token projection) │ ├── Styling/ # MarkdownASTStyler (AST walk) + MarkdownStyler facade for NSImage passes │ ├── Renderer/ # LayoutBridge, MarkdownTextLayoutFragment, EmbeddedImageCache │ ├── Input/ # MarkdownInputHandler + MarkdownListHandler │ ├── TextView/ │ │ ├── NativeTextViewWrapper.swift # SwiftUI entry point (NSViewRepresentable) │ │ ├── NativeTextViewContainer.swift # the scroll view's documentView: header band + text column stacking │ │ ├── ScrollingHeaderController.swift # scroll-away header: hosting, collapse/expand, teardown │ │ ├── ClampedScrollView.swift # scroll range clamped to real content height │ │ ├── NativeTextView/ # AppKit subclass + UX extensions (paste, drag-select, …) │ │ └── Coordinator/ # NSTextViewDelegate split by concern (restyling, find, …) │ └── MarkdownEngine.docc/ # DocC catalog ├── MarkdownEngineCodeBlocks/ # opt-in SPM product — pulls in HighlighterSwift │ └── HighlighterSwiftBridge.swift # SyntaxHighlighter conformance └── MarkdownEngineLatex/ # opt-in SPM product — pulls in SwiftMath └── SwiftMathBridge.swift # LatexRenderer conformance ``` -------------------------------- ### Implement Scrolling Header View Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Host a SwiftUI view above the document body that scrolls away with it. Configure collapsed and expanded states for the header. ```swift NativeTextViewWrapper( text: $text, header: AnyView(MyDocumentHeader(document: document)), headerCollapsedHeight: 40, headerExpanded: isHeaderExpanded ) ``` -------------------------------- ### Observe Wiki-Link State and Inline Replacements Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Use these bindings to manage wiki-link activity and programmatically push inline replacements. Each binding is independent and defaults to a no-operation. ```swift NativeTextViewWrapper( text: $text, isWikiLinkActive: $isWikiLinkActive, pendingInlineReplacement: $pendingReplacement ) ``` -------------------------------- ### Configure Editor SafeAreaInsets Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/CHANGELOG.md Opt-in to explicitly reserve header space for the editor's enclosing scroll view. This is useful when the editor fills its container and relies on the engine reserving header space, such as for a translucent toolbar. ```swift var config = MarkdownEditorConfiguration.default config.safeAreaInsets = SafeAreaInsets(top: 55.4) ``` -------------------------------- ### Customizing Markdown Editor Theme Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/Sources/MarkdownEngine/MarkdownEngine.docc/MarkdownEngine.md Demonstrates how to customize the appearance of the Markdown editor by modifying the default theme. You can change properties like body text and heading marker colors. ```swift var theme = MarkdownEditorTheme.default theme.bodyText = .labelColor theme.headingMarker = .secondaryLabelColor var configuration = MarkdownEditorConfiguration.default configuration.theme = theme ``` -------------------------------- ### Configure Fixed-Width Reading Column Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Set a fixed reading width for long documents to improve readability. Wide tables will break out to the full window width. ```swift var configuration = MarkdownEditorConfiguration.default configuration.readingWidth = 650 ``` -------------------------------- ### Tuning Editor Layout and Behavior Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Adjust various aspects of the Markdown editor's layout and behavior using `MarkdownEditorConfiguration`. This includes scaling font sizes, adjusting heading multipliers, configuring overscroll, list helper visibility, and safe area insets. ```swift var configuration = MarkdownEditorConfiguration.default configuration.codeBlock.fontSizeScale = 0.9 configuration.headings.fontMultipliers = [2.4, 1.8, 1.4, 1.1, 0.9, 0.75] configuration.overscroll.percent = 0.4 configuration.lists.helpersEnabled = false configuration.safeAreaInsets = SafeAreaInsets(top: 56) // headroom under a translucent toolbar ``` -------------------------------- ### Customizing Editor Theme Colors Source: https://github.com/nodes-app/swift-markdown-engine/blob/main/README.md Modify the editor's appearance by customizing the `MarkdownEditorTheme`. This allows you to change default colors for text, highlights, and other UI elements, supporting system light/dark mode. ```swift var theme = MarkdownEditorTheme.default theme.bodyText = .labelColor theme.findMatchHighlight = NSColor(named: "MyAccent")! var configuration = MarkdownEditorConfiguration.default configuration.theme = theme ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.