Skip to content

Add Markdown preview mode - #924

Closed
Gordon Lam (yeelam-gordon) wants to merge 1 commit into
microsoft:mainfrom
yeelam-gordon:feature/markdown-preview
Closed

Add Markdown preview mode#924
Gordon Lam (yeelam-gordon) wants to merge 1 commit into
microsoft:mainfrom
yeelam-gordon:feature/markdown-preview

Conversation

@yeelam-gordon

@yeelam-gordon Gordon Lam (yeelam-gordon) commented Aug 19, 2026

Copy link
Copy Markdown

Summary

  • add a read-only rendered Markdown preview for Markdown documents;
  • toggle preview with View > Markdown Preview or Alt+P;
  • keep preview state and caching independent per document;
  • reuse Edit's TUI, framebuffer, Unicode measurement, scrolling, colors, and localization systems;
  • add no crate dependencies.

Architecture

The implementation separates:

  • markdown_preview/parser.rs: block and inline parsing;
  • markdown_preview/layout.rs: Unicode-aware wrapping and rendered lines;
  • markdown_preview.rs: per-document cache and lifecycle;
  • draw_markdown_preview.rs: TUI drawing only.

The parser is bounded to preserve Edit's responsiveness:

  • 1 MiB maximum preview source;
  • 32 KiB maximum line length;
  • O(1) cache fast path for unchanged buffers;
  • raw-byte validation after generation reuse;
  • bounded forward scanning for malformed links and backtick runs.

Tests

The business-logic tests cover:

  • supported block and inline formatting;
  • malformed and incomplete input;
  • invalid UTF-8;
  • Unicode wrapping and style preservation;
  • cache reuse and content invalidation;
  • undo/edit generation reuse;
  • per-document state and scroll resets;
  • large-file and long-line limits;
  • adversarial bracket and backtick inputs with bounded-work assertions.

Clean-checkout validation:

cargo fmt --all -- --check
cargo clippy --workspace --all-features --all-targets -- --no-deps --deny warnings
cargo test --workspace --all-targets
cargo build --release -p edit

Size

Upstream release binary: 427,520 bytes
Preview release binary:  446,976 bytes
Difference:               +19,456 bytes (+4.55%)

Demo

Markdown preview demo

Limitations

  • lightweight Markdown subset rather than full CommonMark;
  • links are rendered as text and are not clickable;
  • one line over 32 KiB disables preview for that document;
  • localization currently falls back to English for the three new strings.

Closes 923

Render Markdown documents in a scrollable, read-only preview using Edit's native TUI primitives. Keep preview state per document, bound parser work for responsiveness, and add regression coverage for caching, malformed input, Unicode wrapping, and adversarial delimiters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yeelam-gordon

Copy link
Copy Markdown
Author

Closing because I mistakenly opened this draft against the upstream repository. Development and review will continue in the fork PR: yeelam-gordon#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant