Skip to content

feat: implement md-to-html-swift converter #15

Description

@PsychQuantClaw

Summary

Implement a new Layer 3 Swift package: md-to-html-swift for direct Markdown → HTML conversion.

This is the reverse pair of the in-flight html-to-md-swift work and is already promoted to P0 by the conversion matrix rules.

Why

  • html-to-md-swift makes the reverse path architecturally straightforward.
  • Direct Markdown → HTML avoids routing through other hub formats.
  • The CLI should expose a first-class Markdown → HTML command instead of forcing downstream tools to shell out to unrelated renderers.

Proposed package shape

  • New package: packages/md-to-html-swift
  • Layer: Layer 3 (converter/renderer)
  • Product: MDToHTMLSwift
  • Platform: Swift 5.9+, macOS 14+

Dependencies

Layer 2

  • doc-converter-swift
    • use DocumentConverter
    • use StreamingOutput
    • use shared ConversionOptions / ConversionError

Layer 1 / parsing

  • swift-markdown (Apple) for Markdown AST parsing
    • gives a structured parser instead of regex-based rendering
    • keeps the converter target-aware and easier to test

If swift-markdown proves too heavy for the initial cut, start with a minimal internal parser for the supported subset and keep the package boundary compatible with a future parser swap.

Implementation sketch

  • Add MarkdownToHTMLConverter that conforms to DocumentConverter
  • Parse Markdown input into an AST / block sequence
  • Emit HTML through StreamingOutput incrementally
  • Preserve streaming-friendly output APIs (convert(input:output:), convertToString(...))
  • Support core Markdown constructs first:
    • headings
    • paragraphs
    • emphasis / strong / code spans
    • fenced code blocks
    • blockquotes
    • ordered / unordered lists
    • links / images
    • horizontal rules

CLI integration

Add a new macdoc md to-html command (or equivalent Markdown command group consistent with existing CLI conventions).

Test strategy

  • Unit tests for block-level rendering
  • Unit tests for inline rendering and escaping
  • Fixture tests for nested lists, blockquotes, code fences, links, and images
  • CLI smoke test that verifies output file creation and representative HTML fragments
  • Aim for 80%+ coverage in the new package

Acceptance criteria

  • swift test passes from repo root
  • new package builds independently
  • CLI exposes Markdown → HTML conversion
  • CONVERSIONS.md is updated from planned → active/implemented as work progresses

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions