Understand the Editing and Preview Pipelines
mainEditing Pipeline (Hot Path)
Keystrokes flow through EditTextView (a NSTextView subclass with CustomTextStorage) to NSTextStorage.processEditing. Performance is managed by NotesTextProcessor.checkPerformanceLevel:
- Short text: Full Markdown highlighting via
MarkdownRuleHighlighter. - Long/Large text (> 1 MB total OR > 64 KB per paragraph OR > 5000 lines): Simplified highlighting (skips code block regex).
- Medium text (> 2000 lines): Simplified, but code highlighting remains active.
Preview Pipeline
Content flows from Note.content through swift-cmark-gfm to generate an HTML string. Post-render transforms (like math <br> cleanup and GitHub Alerts rewrites) are applied in renderMarkdownHTML. The MPreviewView (WKWebView) loads Resources/DownView.bundle/index.html. Subsequent edits use incremental DOM mutation rather than full reloads.