DEMARK

HTML inMarkdown out

What is Demark?

Demark is a Swift package designed to convert messy, potentially malformed HTML into clean, pristine Markdown. It's the little helper that chomps HTML and spits out beautiful Markdown, perfect for any Swift application needing robust HTML processing.

Born out of the need for a reliable solution to handle real-world HTML, Demark leverages the power of proven JavaScript libraries (Turndown.js & html-to-md) by running them inside a WKWebView. This gives you access to full browser DOM parsing capabilities right within your Swift code.

Two Powerful Engines

Turndown.js (Default)

For Maximum Accuracy:

  • Full DOM-based parsing.
  • Handles complex HTML and JavaScript-rendered content.
  • Comprehensive configuration options.
  • ~100ms for first conversion, then much faster.
html-to-md

For Blazing Speed:

  • Lightweight JavaScript-based conversion.
  • Much faster performance (~5-10ms per conversion).
  • Perfect for batch processing simpler HTML.

Simple to Use

Swift Example
import Demark

@MainActor 
func convertHTML() async throws {
    let demark = Demark()
    let html = "<h1>Hello World</h1><p>This is <strong>bold</strong> text.</p>"
    let markdown = try await demark.convertToMarkdown(html)
    print(markdown)
    // Output: 
    // # Hello World
    //
    // This is **bold** text.
}

Demark works across all Apple platforms: iOS, macOS, watchOS, tvOS, and visionOS.

Stay Updated

2× per month, pure signal, zero fluff.