Skip to content

Add live Markdown preview#62

Merged
GordonBeeming merged 7 commits into
mainfrom
gb/markdown-live-preview
Jul 17, 2026
Merged

Add live Markdown preview#62
GordonBeeming merged 7 commits into
mainfrom
gb/markdown-live-preview

Conversation

@GordonBeeming

@GordonBeeming GordonBeeming commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Add live Markdown preview

Summary

  • Add an opt-in live preview for .md and .markdown files.
  • Keep the CodeMirror editor mounted when the preview is shown or hidden.
  • Render Mermaid fenced diagrams lazily with strict Mermaid security settings.
  • Sanitize rendered Markdown and contain primary and auxiliary link navigation.
  • Debounce rendering and skip preview work while the pane is hidden.
  • Prevent accidental text selection across app HTML while preserving selection in editors and editable controls.

Why

Markdown files currently have no rendered view inside ide. This adds a safe split preview while preserving the existing editing experience and editor state.

User impact

Users can enable Markdown preview under Preview Features, then show a live rendered pane beside supported Markdown files. The feature is default-off while it remains in preview.

App HTML no longer behaves like selectable webpage text; CodeMirror, rename fields, search boxes, and other editable controls remain selectable.

Validation

  • ./run-tests.sh
  • 425 frontend tests passed
  • 238 Rust tests passed
  • Production build, smoke tests, bundle budgets, formatting, linting, configuration checks, and dependency audits passed
  • Live preview and Mermaid rendering visually verified against azure-architecture.md
  • Preview lifecycle and primary/auxiliary link containment tested

Copilot AI review requested due to automatic review settings July 17, 2026 00:00
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a feature-flagged Markdown preview with sanitized rendering, debounced updates, resizable split panes, external link handling, persistence support, and application/component tests.

Changes

Markdown Preview Feature

Layer / File(s) Summary
Feature flag and persistence
src/featureFlags.ts, src/featureFlags.test.ts, src-tauri/src/lib.rs
Registers markdownPreview as a disabled preview flag and preserves it through settings sanitization and UI-state round trips.
Markdown rendering and split-pane behavior
package.json, src/MarkdownPreview.tsx, src/markdownRenderer.ts, src/MarkdownPreview.css, src/MarkdownPreview.test.tsx
Adds sanitized Markdown rendering, debounced updates, scroll restoration, resizable panes, external link handling, accessibility behavior, styling, and related tests.
Application integration
src/App.tsx, src/styles.css
Detects Markdown files, adds a preview toggle, preserves the editor as content and fallback, conditionally mounts MarkdownPreview, and updates selection behavior.
Application behavior coverage
src/App.test.tsx
Tests feature-gated visibility, Markdown file transitions, disk reloads, unsaved edits, preview controls, and refocus timing.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant App
  participant MarkdownPreview
  participant markdownRenderer
  participant Editor
  User->>App: Open Markdown file and enable preview
  App->>MarkdownPreview: Pass editor content and visibility
  MarkdownPreview->>Editor: Render editor children
  MarkdownPreview->>markdownRenderer: Parse and sanitize Markdown
  markdownRenderer-->>MarkdownPreview: Return sanitized HTML
  MarkdownPreview-->>User: Display preview and resize controls
Loading

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding an opt-in live Markdown preview.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch gb/markdown-live-preview

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a live, split-pane Markdown preview feature gated behind a new markdownPreview feature flag, adding dompurify and marked as dependencies. Feedback on the implementation highlights critical lifecycle and state management issues in MarkdownPreview.tsx, specifically a scroll position leak when switching files, a stale preview flash, and redundant parsing. Additionally, it is recommended to wrap the Markdown parsing logic in a try-catch block to prevent potential rendering crashes from malformed input.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/MarkdownPreview.tsx
Comment thread src/MarkdownPreview.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/App.tsx`:
- Line 208: Update the MarkdownPreview lazy-loading flow so the stateful
EditorPane is not used as or recreated across the Suspense fallback boundary.
Keep the editor wrapper synchronously imported, or lazy-load only the rendered
preview pane, ensuring the same editor instance preserves focus, selection,
history, and local state.
- Around line 6080-6083: Add a React key based on activeFile.path to the
MarkdownPreview component so it remounts when navigating directly between
Markdown files, resetting its rendered HTML and scroll state immediately.
Preserve the existing preview props and visibility behavior.

In `@src/MarkdownPreview.css`:
- Around line 7-8: Insert a blank line after the --markdown-editor-width custom
property and before the display declaration in the stylesheet.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0749e5c9-4b92-4b6f-8239-defb9d954217

📥 Commits

Reviewing files that changed from the base of the PR and between bae8dc4 and fc853ce.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (9)
  • package.json
  • src-tauri/src/lib.rs
  • src/App.test.tsx
  • src/App.tsx
  • src/MarkdownPreview.css
  • src/MarkdownPreview.test.tsx
  • src/MarkdownPreview.tsx
  • src/featureFlags.test.ts
  • src/featureFlags.ts

Comment thread src/App.tsx Outdated
Comment thread src/App.tsx Outdated
Comment thread src/MarkdownPreview.css Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in live Markdown preview pane (gated behind a new markdownPreview preview feature flag) that renders sanitized Markdown alongside the existing editor while keeping the editor mounted and debouncing preview updates.

Changes:

  • Introduces a new MarkdownPreview split-pane component with sanitization, scroll preservation, and link interception.
  • Adds the markdownPreview preview feature flag end-to-end (frontend registry/tests + Rust KNOWN_FEATURE_FLAGS + state sanitization tests).
  • Wires the preview toggle and conditional rendering into App, with new UI-level tests and new npm dependencies (marked, dompurify).

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/MarkdownPreview.tsx New split-pane renderer: debounced Markdown → HTML → DOMPurify sanitize, link click containment, resize handle, scroll handling.
src/MarkdownPreview.test.tsx Component tests for debouncing, scroll preservation, sanitization, link handling, and resize keyboard support.
src/MarkdownPreview.css New styling for the preview split pane and rendered Markdown surface.
src/featureFlags.ts Adds markdownPreview to the feature flag registry as a preview flag.
src/featureFlags.test.ts Updates feature flag resolution/listing tests for the new flag.
src/App.tsx Adds toggle button + conditional Markdown-only preview wrapper around the editor pane.
src/App.test.tsx Adds app-level tests covering flag gating and Markdown-only preview behavior across edits/reloads/files.
src-tauri/src/lib.rs Adds markdownPreview to KNOWN_FEATURE_FLAGS and updates sanitization/load tests.
package.json Adds dompurify and marked dependencies.
package-lock.json Locks new dependencies and transitive additions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/MarkdownPreview.tsx Outdated
Comment thread src/MarkdownPreview.tsx Outdated
Comment thread src/MarkdownPreview.css Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc853ce040

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/MarkdownPreview.tsx Outdated
Comment thread src/MarkdownPreview.tsx
Copilot AI review requested due to automatic review settings July 17, 2026 00:12
@GordonBeeming

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/MarkdownPreview.tsx (1)

51-67: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Restore scroll position when visibility changes.

The layout effect only depends on html. When visible changes from false to true with unchanged contents, React can skip the identical setHtml update, so the newly mounted preview does not restore previewScrollTop.current.

Proposed fix
-  }, [html]);
+  }, [html, visible]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/MarkdownPreview.tsx` around lines 51 - 67, The scroll-restoration effect
in MarkdownPreview must also run when visibility changes. Update the
useLayoutEffect dependency list to include visible alongside html, preserving
the existing preview.current and previewScrollTop.current behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/MarkdownPreview.tsx`:
- Around line 51-63: Update the lazy renderer loading in the useEffect hook to
add a rejection path after import("./markdownRenderer").catch failures, logging
the error and setting a graceful preview error state. Preserve the cancelled
guard so failed or late loads do not update state after cleanup, and include any
required error state rendering alongside the existing setHtml flow.

---

Outside diff comments:
In `@src/MarkdownPreview.tsx`:
- Around line 51-67: The scroll-restoration effect in MarkdownPreview must also
run when visibility changes. Update the useLayoutEffect dependency list to
include visible alongside html, preserving the existing preview.current and
previewScrollTop.current behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8bb5feb4-105b-47dd-9ecf-1946161714eb

📥 Commits

Reviewing files that changed from the base of the PR and between fc853ce and f80beff.

📒 Files selected for processing (7)
  • src/App.test.tsx
  • src/App.tsx
  • src/MarkdownPreview.css
  • src/MarkdownPreview.test.tsx
  • src/MarkdownPreview.tsx
  • src/markdownRenderer.ts
  • src/styles.css
💤 Files with no reviewable changes (1)
  • src/MarkdownPreview.css
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/MarkdownPreview.test.tsx
  • src/App.tsx
  • src/App.test.tsx

Comment thread src/MarkdownPreview.tsx
@GordonBeeming

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Comment thread src/styles.css
Comment thread src/MarkdownPreview.tsx Outdated
Comment thread src/markdownRenderer.ts
Copilot AI review requested due to automatic review settings July 17, 2026 00:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ded3edaf1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/markdownRenderer.ts Outdated
Comment thread src/styles.css

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Comment thread src/styles.css
Copilot AI review requested due to automatic review settings July 17, 2026 00:28
@GordonBeeming

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Comment thread src/styles.css
Comment thread src/markdownRenderer.ts
Comment thread package.json Outdated
Copilot AI review requested due to automatic review settings July 17, 2026 00:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 852e77668a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/styles.css

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Comment thread src/MarkdownPreview.tsx
Copilot AI review requested due to automatic review settings July 17, 2026 00:37
@GordonBeeming

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d66abb839

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/styles.css
@GordonBeeming
GordonBeeming merged commit 8dcc501 into main Jul 17, 2026
3 of 5 checks passed
@GordonBeeming
GordonBeeming deleted the gb/markdown-live-preview branch July 17, 2026 00:55
Copilot stopped reviewing on behalf of GordonBeeming due to an error July 17, 2026 00:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Comment thread src/styles.css
Comment on lines 265 to +277
overflow: hidden;
background: var(--bg);
color-scheme: inherit;
user-select: none;
zoom: var(--app-zoom, 1);
}

input,
textarea,
.cm-content,
[contenteditable="true"] {
user-select: text;
}
Comment thread src/MarkdownPreview.tsx
Comment on lines +141 to +152
: "minmax(0, 1fr)",
minHeight: 0,
overflow: "hidden",
} as CSSProperties}
>
<div
className="markdown-preview-split__editor"
style={{ minWidth: 0, minHeight: 0, overflow: "hidden" }}
>
{children}
</div>
{visible ? (
Copilot AI review requested due to automatic review settings July 17, 2026 00:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated no new comments.

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.

2 participants