Ted Mwai
All works
Web & ProductivityDOM-SYSAugust 2026

In-Browser Markdown Studio

Instant-render offline workspace for documentation writers and technical bloggers

< 4ms
Input-to-Paint Latency
10,000+ Lines
Document Scale
100% PWA
Offline Support

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.

TypeScriptWeb ComponentsAstroWeb WorkersWASM
Executive summary
DOSSIER // TL;DR

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.

Outcome

Maintains sub-4ms input-to-paint authoring latency across 10,000+ line technical documents with 100% offline PWA availability.

Method

TypeScript Web Components workspace offloading Markdown AST parsing and KaTeX math compilation to Web Workers with proportional line-anchor scroll sync.

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 on 10,000+ line documents.
  • Zero-Script Export Hygiene: Exported standalone .html artifacts 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

  1. 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.
  2. AST Line-Anchor Scroll Synchronization:
    • Injects lightweight data-source-line block markers during AST compilation and interpolates viewport offsets between adjacent block anchors—preventing preview drift across tall fenced code blocks and tables.
  3. Self-Contained Static Bundle Exporter:
    • Serializes rendered HTML alongside scoped typography/theme CSS variables into a clean, single-file .html download with zero external scripts.

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 < 4ms P95 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

Cross-posting & syndication
Canonical URL: https://tedcraft.dev/works/markdown-viewer/
Syndicate or reference this case-study with canonical attribution