Skip to content

cocoar-dev/Cocoar.Markdown

Cocoar.Markdown

A SwiftUI markdown viewer with native custom embeds — render markdown prose and drop fully interactive SwiftUI views between the paragraphs, driven by plain-text directives.

2. Den Teig zu einer Kugel formen und abgedeckt ruhen lassen.

:::timer{min=10 label="Teig ruhen"}

3. Ofen auf 180 °C vorheizen.

The :::timer{…} line above renders as whatever SwiftUI view your app registers for the timer key — a live countdown, a map, a chart. Unknown keys render as a visible fallback chip; content is never lost and never shown as raw text.

Wire syntax

Embeds are standalone lines of the form :::key{attr=value attr2="quoted" flag}. The syntax is shared with the web implementation in @cocoar/vue-markdown-core (its embed-directive.ts is the normative spec — this repo is a byte-parity port, see Conformance).

Usage

import CocoarMarkdownUI

var registry = EmbedRegistry()
registry.register("timer") { props in
    TimerChipView(minutes: Int(props["min"] ?? "") ?? 0,
                  label: props["label"] ?? "Timer")
}

var body: some View {
    ScrollView {
        CocoarMarkdownView(source: document, registry: registry)
            .cocoarMarkdownTheme(.init(accent: .green))   // optional host-app theming
    }
}
  • CocoarMarkdownCore — dependency-free parser, serializer and document segmenter for the directive syntax.
  • CocoarMarkdownUICocoarMarkdownView (prose via MarkdownUI), EmbedRegistry, and CocoarMarkdownTheme (environment-based theming: accent/info/warning tints, spacing, corner radius — neutral, light/dark-safe defaults).

Installation

.package(url: "https://github.com/cocoar-dev/Cocoar.Markdown.git", from: "0.1.0")

Platforms: iOS 17+, macOS 14+.

Demo

Demo/ contains a demo app (XcodeGen): a recipe document with an interactive cooking timer, callouts, a warning row, an unregistered embed showing the fallback chip, a source/rendered flip and a theme switcher.

cd Demo && xcodegen generate && open CocoarMarkdownDemo.xcodeproj

Conformance

Web and Swift are held together by a shared vector suite — the same embed-directive.conformance.json runs through Vitest (web, normative copy) and XCTest (here, vendored copy synced via Scripts/sync-vectors.sh); CI additionally diffs the vendored copy against the normative source on every push and weekly. See CONFORMANCE.md for the workflow and the capability matrix.

License

Apache License 2.0 — see LICENSE, NOTICE and TRADEMARKS.md.

About

SwiftUI markdown viewer with native custom embeds — :::key{props} directives, embed registry, theming. Byte-parity port of @cocoar/vue-markdown-core's embed syntax.

Resources

License

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors