Contents

swift-foundations/swift-markdown-html-render

Renders Markdown to HTML as composable HTML.View values, with customizable per-element rendering, heading slugs, block directives, and table-of-contents extraction.

Key Features

  • Renders to an HTML.View — Markdown becomes a typed HTML view that composes inside any HTML document tree, not just a flat string.
  • Per-element rendering — Override how headings, paragraphs, code blocks, lists, tables, and inline elements render through Markdown.Rendering.
  • Configurable heading slugsMarkdown.Configuration.SlugGenerator offers .default, .prefixed(:), and .custom(:) strategies, deduplicated across a document.
  • Block directives — Handle custom @Name(...) directives with your own renderer via Markdown.Configuration.Directives.
  • Table of contentsMarkdown.tableOfContents(from:) extracts headings as Section values carrying id, level, and timestamp.
  • Transcript timestamps@T(0:00) Speaker directives parse into Timestamp values for time-coded content.
  • GitHub-flavored elements — Tables, strikethrough, fenced code blocks with language and line-highlight info, and block-quote asides mapped to diagnostic levels.

Quick Start

Markdown renders to a typed HTML.View, so it composes directly inside an HTML document alongside the rest of your view tree:

import Markdown_HTML_Rendering

let html = try String(
    Markdown {
        """
        # Changelog

        Version 2 adds **typed throws** end to end.

        - Composes into any HTML view tree
        - Custom per-element rendering
        """
    }
)

Headings followed by a @T(...) timestamp directive are collected into a table of contents:

let sections = Markdown.tableOfContents(from: """
    # Intro
    @T(0:00)
    Welcome.

    # Deep Dive
    @T(2:15)
    Details.
    """)
// sections[0].id == "intro"
// sections[0].timestamp?.duration == 0

Installation

dependencies: [
    .package(url: "https://github.com/swift-foundations/swift-markdown-html-render.git", branch: "main")
]
.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "Markdown HTML Rendering", package: "swift-markdown-html-render")
    ]
)

Requires Swift 6.3.1 and macOS 26 / iOS 26 / tvOS 26 / watchOS 26 / visionOS 26.


Architecture

Three library products. Importing Markdown HTML Rendering also brings the HTML rendering, CSS, and SwiftMarkdown parse types into scope.

| Product | When to import | |---------|----------------| | Markdown HTML Rendering | Rendering Markdown to HTML — the Markdown view, Markdown.Configuration, Markdown.Rendering, and Markdown.tableOfContents(from:). | | Markdown HTML Rendering Test Support | Test targets that render Markdown and assert against the output; re-exports the main module and Swift Testing. | | Markdown Previews | Xcode #Preview gallery of rendered Markdown elements (SwiftUI; macOS and iOS only). |


Community

Discussion thread will be created at first public release.

License

Apache 2.0. See LICENSE.

Package Metadata

Repository: swift-foundations/swift-markdown-html-render

Default branch: main

README: README.md