In-Browser Markdown Studio
Instant-render offline workspace for documentation writers and technical bloggers
How measured · Input-to-paint latency (< 4ms P95) measured via Chrome DevTools Performance frame timing while typing continuously inside a synthetic 10,000-line Markdown + KaTeX specification.
Long technical specifications with dense math lag on main-thread editors and drift during scrolling. This local-first Markdown studio moves AST and KaTeX rendering off the main thread into Web Workers and exports clean static HTML bundles.
Maintains sub-4ms input-to-paint authoring latency across 10,000+ line technical documents with 100% offline PWA availability.
TypeScript Web Components workspace offloading Markdown AST parsing and KaTeX math compilation to Web Workers with proportional line-anchor scroll sync.
Jump to sectionTOC
Problem
Technical authors writing long-form runbooks, RFCs, and security post-mortems hit two recurring friction points in standard web Markdown editors: keystrokes lag once documents exceed several thousand lines with embedded LaTeX/KaTeX equations, and naive percentage-based scroll synchronization drifts badly whenever code blocks or diagrams have different source-vs-rendered heights.
Constraints
- Strict Local-First Privacy: Draft runbooks and pre-disclosure post-mortems could never leave the browser over network API calls; storage, parsing, and HTML export had to operate
100%offline. - Sub-Frame Input Budget: Main-thread keystroke handling had to stay well under the
16.6ms(60Hz) frame budget even on10,000+line documents. - Zero-Script Export Hygiene: Exported standalone
.htmlartifacts had to be safe to archive or share without external CDN or runtime<script>dependencies.
My Contribution
I architected and built the TypeScript Web Components editor shell, implemented the off-main-thread Web Worker AST and KaTeX pipeline, wrote the AST source-line proportional scroll synchronizer, and configured Service Worker offline caching.
Architecture
- Off-Main-Thread Worker Pipeline:
- Main thread handles raw text input and cursor state only, posting debounced document diffs to a dedicated Web Worker that executes Markdown tokenization, AST transformation, and KaTeX math layout off the UI thread.
- AST Line-Anchor Scroll Synchronization:
- Injects lightweight
data-source-lineblock markers during AST compilation and interpolates viewport offsets between adjacent block anchors—preventing preview drift across tall fenced code blocks and tables.
- Injects lightweight
- Self-Contained Static Bundle Exporter:
- Serializes rendered HTML alongside scoped typography/theme CSS variables into a clean, single-file
.htmldownload with zero external scripts.
- Serializes rendered HTML alongside scoped typography/theme CSS variables into a clean, single-file
Verification
- 10,000-Line Stress Profiling: Recorded Chrome DevTools Performance traces under sustained typing and rapid scrolling on a
10,000+line corpus containing fenced code blocks, tables, and KaTeX formulas, confirming< 4msP95 input-to-paint latency and zero long tasks (> 50ms) on the main thread. - Offline Airplane-Mode Validation: Verified cold reload, IndexedDB draft persistence, math rendering, and HTML bundle export with network interfaces disabled.
Results
- Zero Typing Lag at Scale: Eliminated main-thread parser stalls on multi-thousand-line technical specifications.
- Deterministic Offline Authoring: Enabled air-gapped and travel-ready technical writing with one-click archival HTML output.
Evidence
- Author Repositories & Tooling: teddymwai on GitHub
- Related UI Performance Notes: Taming Real-Time Layout Thrashing in Live Telemetry Dashboards
https://tedcraft.dev/works/markdown-viewer/