Skip to content

Add bidirectional Markdown/RTF conversion#33

Open
DandyLyons wants to merge 1 commit into
mainfrom
feat/to-from-rich-text
Open

Add bidirectional Markdown/RTF conversion#33
DandyLyons wants to merge 1 commit into
mainfrom
feat/to-from-rich-text

Conversation

@DandyLyons

Copy link
Copy Markdown
Owner

Summary

  • Implement Markdown → RTF conversion (RTFConverter) using NSAttributedString, supporting headings, bold, italic, inline code, code blocks, links, lists, blockquotes, strikethrough, and thematic breaks
  • Implement RTF → Markdown conversion (RTFGenerator) using font-size/weight heuristics for heading detection, monospace detection for code blocks, and attribute enumeration for inline formatting
  • Add md-utils convert to-rtf and md-utils convert from-rtf CLI commands following existing ToText pattern (stdin/file/batch modes)

Closes #13

Test plan

  • 15 RTFConverter tests verify Markdown→RTF attribute fidelity (bold, italic, code, links, lists, headings, strikethrough, blockquotes, custom fonts)
  • 11 RTFGenerator tests verify RTF→Markdown detection (bold, italic, inline code, links, strikethrough, headings, code blocks, error handling)
  • 5 round-trip tests verify structural equivalence (headings, bold/italic, inline code, links, paragraphs)
  • All 746 tests pass (swift test)
  • swift run md-utils convert to-rtf --help shows correct usage
  • swift run md-utils convert from-rtf --help shows correct usage
  • Manual: swift run md-utils convert to-rtf README.md -o test.rtf → open in TextEdit → verify formatting
  • Manual: swift run md-utils convert from-rtf test.rtf → verify Markdown output

🤖 Generated with Claude Code

Implement Markdown → RTF and RTF → Markdown conversion using
NSAttributedString, with library API, CLI commands, and tests.

Library: RTFConverter walks AST to build attributed strings with
formatted headings, bold, italic, code, links, lists, and
blockquotes. RTFGenerator uses font-size/weight heuristics to
detect headings, monospace detection for code blocks, and
attribute enumeration for inline formatting.

CLI: `md-utils convert to-rtf` and `md-utils convert from-rtf`
follow the existing ToText pattern with stdin/file/batch modes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Markdown to/from rich text conversion

1 participant