Add HTML and PDF conversation export

Top item on the roadmap ranking from 2026-07-27 — multi-modal export
alongside the existing Markdown/JSON. New ConversationExportService
consolidates the two previously-duplicated Markdown builders
(ChatViewModel and ConversationListView had separate copies of the
same **User**/**Assistant** + --- format) and adds:

- A hand-rolled Markdown->HTML renderer scoped to what actually shows
  up in chat messages (headers, bold/italic, inline code, fenced code
  blocks, lists, blockquotes, links, horizontal rules) rather than
  full CommonMark/GFM — no existing markdown-to-HTML utility existed
  in the codebase, and swift-markdown-ui is SwiftUI-view-only with no
  HTML-string export API. Content is HTML-escaped before any markdown
  substitution so example code containing "<div>" etc renders as
  visible text, not live markup.
- PDF via an offscreen WKWebView loading that same HTML and calling
  the official createPDF(configuration:) API (macOS 11+) — no new
  project/framework linkage needed, WebKit is a system framework.

Wired into every place Markdown export already existed: File menu
(Export as HTML.../PDF...), /export slash command (now md|html|pdf|json),
and a new Export submenu (Markdown/HTML/PDF) on each conversation row's
context menu in the advanced conversation list, replacing the old
single-format swipe-only export. Help docs and InputBar autocomplete
updated to match.
This commit is contained in:
2026-07-29 07:47:57 +02:00
parent 727fc7d6af
commit 634b83f284
8 changed files with 562 additions and 34 deletions
@@ -260,8 +260,8 @@
<dt>/delete &lt;name&gt;</dt>
<dd>Delete a saved conversation</dd>
<dt>/export md|json</dt>
<dd>Export conversation as Markdown or JSON</dd>
<dt>/export md|html|pdf|json</dt>
<dd>Export conversation as Markdown, HTML, PDF, or JSON</dd>
</dl>
<h3>MCP Commands</h3>
@@ -567,10 +567,12 @@
</ol>
<h3>Exporting Conversations</h3>
<p>Export to Markdown or JSON format:</p>
<p>Export to Markdown, HTML, PDF, or JSON format:</p>
<code class="command">/export md</code>
<code class="command">/export html</code>
<code class="command">/export pdf</code>
<code class="command">/export json</code>
<p class="note">Files are saved to your Downloads folder.</p>
<p class="note">Files are saved to your Downloads folder. HTML and PDF export are also available from File → Export as HTML…/PDF…, and per-conversation from the Export submenu in the conversation list's context menu.</p>
</section>
<!-- Git Sync -->