To create a high-fidelity macOS Quick Look (QuickView) Extension for Markdown files that replicates the rendering experience of the "Markdown Preview Enhanced" (MPE) VS Code plugin.
Note: This macOS app is named FluxMarkdown. The mention of "Markdown Preview Enhanced (MPE)" refers to the VS Code plugin this project was inspired by.
Decision: We use a Native Swift Container hosting a Web-based Renderer (WKWebView).
- Why?: Markdown rendering is complex. Re-implementing GFM, Mermaid, KaTeX, and syntax highlighting in pure Swift is impractical and would deviate from the MPE look-and-feel.
- Benefit: We can reuse the vast JavaScript ecosystem (
markdown-it,mermaid,katex) that MPE is built on. - Trade-off: Slightly higher memory usage than a native text view, but significantly richer feature set.
Decision: Reconstruct the rendering stack using Client-Side Libraries (markdown-it + plugins) instead of porting the MPE core (mume).
- Reason: The original
@shd101wyy/mumeengine is heavily dependent on Node.js APIs (fs,path,child_process). macOS Quick Look extensions run in a strict App Sandbox without a Node.js runtime. - Impact:
- ✅ Preserved: Markdown syntax, Math (KaTeX), Diagrams (Mermaid), Syntax Highlighting.
- ❌ Dropped: Code Chunk execution (security/runtime limit), Local File Imports (sandbox limit), PDF Export (viewer only).
Decision: Use github-markdown-css as the base, supplemented by highlight.js themes.
- Reason: Copying Atom/Less styles from the original project introduces dependency on Atom-specific DOM structures. Standardizing on GitHub's CSS ensures reliability and easier maintenance while maintaining a familiar look.
graph TD
A[macOS Finder / Spotlight] -->|User selects file| B(Quick Look Extension)
B -->|Swift: Prepare Preview| C{PreviewViewController}
C -->|Read File Content| D[String Buffer]
C -->|Load WebView| E[WKWebView]
E -->|Load| F[Local HTML/JS Bundle]
D -->|Inject JSON via JS| F
F -->|Render| G[DOM Output]
subgraph "Web Renderer (Sandbox)"
F --> H[markdown-it]
H --> I[Plugins: Katex, Emoji, etc.]
F --> J[Mermaid.js]
F --> K[Highlight.js]
end
- Establish isolated project structure.
- Create
web-rendererbuild pipeline (Webpack + TypeScript). - Implement core rendering logic (Markdown -> HTML -> Diagrams).
- Generate Swift integration code (
PreviewViewController).
- Create the actual Xcode Project (
.xcodeproj). - Integrate the
dist/bundle into the App Bundle Resources. - Configure
Info.plistfor UTI support (net.daringfireball.markdown). - Verify App Sandbox entitlements.
- Performance: Optimize
bundle.jssize; implement lazy loading for heavy libraries if needed. - Styling: Fine-tune CSS to match macOS System Appearance (Light/Dark mode auto-switching).
- Error Handling: Graceful fallback for malformed Markdown or JS errors.
- Network Access: Enable Client-Side Network entitlement to support external images (Note: Privacy implications).
- Search: Implement
QLSupportsSearchableItemsto allow Spotlight to index rendered content (text extraction).
- Transform the Host App into a full-featured Markdown Viewer.
- Support local file browsing, image rendering, and navigation.
- See DESIGN_HOST_APP_BROWSER.md for detailed architecture.
- Modify Renderer:
- Edit
web-renderer/src/index.tsor CSS. - Run
npm run build.
- Edit
- Update Xcode:
- Xcode should automatically pick up changes in the linked
dist/folder. - Re-run the macOS Scheme.
- Xcode should automatically pick up changes in the linked
- Debug:
- Use Safari Web Inspector to debug the
WKWebViewinside the Quick Look simulator.
- Use Safari Web Inspector to debug the