Skip to content

fix(rich-md-editor): raw-HTML-block fragmentation + styling follow-up#5440

Merged
waleedlatif1 merged 5 commits into
stagingfrom
investigate/markdown-source-editing
Jul 6, 2026
Merged

fix(rich-md-editor): raw-HTML-block fragmentation + styling follow-up#5440
waleedlatif1 merged 5 commits into
stagingfrom
investigate/markdown-source-editing

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #5438 (already merged) — two issues found during manual testing after merge:

  • Fragmentation bug: RawHtmlBlock delegated to marked's built-in block-HTML tokenizer, which (per CommonMark's HTML-block-type-6 rule) stops at the first blank line. A real <details> with a paragraph inside — the common case — fragmented into a raw chip, an ordinary rendered paragraph, and a second raw chip, stranding real content in between. Fixed with a custom block-level tokenizer that scans to the tag's matching close (reusing the balanced open/close depth-tracking already built for nested inline HTML), spanning blank lines, restricted to CommonMark's own block-tag whitelist (details, div, table, section, etc.) — tags that can legitimately start a paragraph (em, a, span, code, kbd) are left untouched.
  • Styling: dropped the warning-colored tint on raw HTML/footnote blocks (color-mix with --warning read as an error/warning state, which isn't the right signal) in favor of the same neutral surface as existing code blocks — the hover badge alone now conveys "this is raw, unrendered text".

Type of Change

  • Bug fix
  • UI polish

Testing

Added 8 new tests specifically targeting the fragmentation fix (structural node-count assertions, not just string round-trip): multi-paragraph <details>, multi-paragraph <div>, nested same-tag blocks across blank lines, a paragraph starting with a non-whitelisted inline tag (regression guard so <em>/<a> still parse as real marks), a stray non-whitelisted tag alone on a line, an unterminated tag (no crash), a comment spanning blank lines, and a table+code-block adjacency check. 236/236 tests passing in the directory, full tsc --noEmit clean, biome clean.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 6, 2026 9:02pm

Request Review

@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes markdown parse/serialize behavior for block HTML in the file viewer editor; mistakes could mis-bound tags or alter document structure on save, though scope is limited to the rich-markdown verbatim path and is heavily tested.

Overview
Fixes raw HTML block fragmentation in the rich markdown editor: marked’s block-HTML rule used to stop at the first blank line, so constructs like <details> with body paragraphs split into multiple raw chips and normal paragraphs. RawHtmlBlock now registers a custom block tokenizer that, for CommonMark’s block-tag whitelist (details, div, table, etc.), scans to the matching closing tag across blank lines via shared findBalancedCloseEnd logic (with code/fence/comment masking and attribute-aware tag matching). Non-whitelisted tags and unterminated blocks still fall through to marked; void block tags (meta, link, hr) close immediately.

UI: raw HTML/footnote snippets drop the warning-tinted background in favor of the same neutral surface as inline code/pre (hover badge still signals “raw”).

Tests add structural assertions (topLevelTypes) and many edge cases (nested blocks, indented opens, quoted > in attributes, tag mentions in code/comments, void tags, graceful degradation).

Reviewed by Cursor Bugbot for commit c043d9c. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes raw HTML handling in the rich markdown editor. The main changes are:

  • Custom block tokenizing for raw HTML blocks that span blank lines.
  • Balance scanning that handles indentation, quoted attributes, code regions, comments, and void tags.
  • Structural tests for raw HTML block parsing and round-tripping.
  • Neutral raw markdown styling aligned with code block surfaces.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/raw-markdown-snippet.tsx Adds the raw HTML block tokenizer and shared balance-scanning helpers for raw HTML preservation.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/raw-markdown-snippet.test.ts Adds parser and round-trip coverage for the raw HTML block cases touched by this change.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-editor.css Updates raw markdown block and inline styling to use neutral editor surfaces.

Reviews (5): Last reviewed commit: "fix(rich-md-editor): mask HTML comments ..." | Re-trigger Greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

- RawHtmlBlock previously delegated to marked's built-in block-HTML tokenizer, which (per CommonMark's HTML-block-type-6 rule) stops at the first blank line. A real <details> with a paragraph inside — the common case — fragmented into a raw chip, an ordinary rendered paragraph, and a second raw chip, stranding real content in between.
- Fixed with a custom block-level tokenizer that scans to the tag's matching close (reusing the balanced open/close depth-tracking already built for nested inline HTML), spanning blank lines, restricted to CommonMark's own block-tag whitelist (details, div, table, section, etc.) so tags that can legitimately start a paragraph (em, a, span, code, kbd) are left untouched.
- Dropped the warning-colored tint on raw HTML/footnote blocks (color-mix with --warning read as an error state) in favor of the same neutral surface as existing code blocks — the hover badge alone now signals "this is raw, unrendered text".
…ention edge cases

- CommonMark allows up to 3 leading spaces before a block-HTML opening line; the new block tokenizer required column 0, so an indented <details>/<div> still fragmented across blank lines. Fixed by splitting off the leading indent, matching against the rest, and stitching the indent back onto raw.
- The open-tag and balanced-close regexes stopped at the first `>`, even inside a quoted attribute value (e.g. data-example="a > b"), producing wrong match lengths and miscounting a same-tag mention inside the quoted value as a real nested tag. Replaced with an attribute-aware pattern that treats a full quoted value (including any interior >) as one unit.
- The balanced-tag scan couldn't distinguish real markup from a tag name mentioned inside inline code or a fenced code block. Now masks code regions (same-length filler, positions preserved) before scanning, so a properly-escaped mention (backticks or a fenced example) is never miscounted. A genuinely bare, unescaped mention outside code remains a known, inherent limitation of regex-based tag matching (shared by real HTML parsers given the same ambiguous input) — verified this can never lose data or hang, only reflow to a stable fixpoint on save.
…ce scan

- maskCodeRegions's fenced-code regex required fence markers at column 0, so a fence quoted inside a markdown blockquote (each line prefixed with `> `) wasn't recognized, leaving tag mentions inside it visible to the balance scanner. Extended the fence pattern to tolerate an optional blockquote prefix on both the opening and closing fence line.
- BLOCK_HTML_TAG_NAMES includes several void elements (link, meta, base, hr, ...) that have no closing tag at all. The block tokenizer only treated an explicit self-closing `/>` as complete, so a void tag without one would scan the rest of the document for a `</meta>` that will never appear, risking a false match on a later same-name mention. Now reuses the existing VOID_TAGS set (already used by the inline tokenizer) to treat these as complete right after the open tag. Also restored `hr` to the whitelist, which was accidentally dropped when transcribing marked's tag list.
@waleedlatif1 waleedlatif1 force-pushed the investigate/markdown-source-editing branch from 7ef46eb to 0ea00f3 Compare July 6, 2026 20:45
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

…code masking

maskCodeRegions's fence pattern handled a blockquoted fence (`> \`\`\``) but still required the
fence marker at column 0 otherwise, missing CommonMark's independent up-to-3-space fence indent
tolerance this codebase already relies on elsewhere (FENCE_OPEN/FENCE_CLOSE in markdown-parse.ts).
An indented fence's tag-name mention could still end a whitelisted block early. Fixed by combining
both allowances in one prefix pattern (zero-or-more blockquote levels, each independently followed
by up to 3 more spaces of indent).
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

A tag-name mention inside an HTML comment (e.g. `<!-- see </div> below -->`)
inside a whitelisted raw HTML block could still be matched by the balance
scan and end the block early, fragmenting it. maskCodeRegions already masked
fenced/inline code the same way; extend it to mask comments too.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c043d9c. Configure here.

@waleedlatif1 waleedlatif1 merged commit 018283b into staging Jul 6, 2026
13 checks passed
@waleedlatif1 waleedlatif1 deleted the investigate/markdown-source-editing branch July 6, 2026 21:10
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