Skip to content

Preserve HTML embeds when editing Docs - #5306

Closed
alanagoyal wants to merge 10 commits into
get-bb:mainfrom
alanagoyal:fix/docs-preserve-html
Closed

alanagoyal wants to merge 10 commits into
get-bb:mainfrom
alanagoyal:fix/docs-preserve-html

Conversation

@alanagoyal

@alanagoyal alanagoyal commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

bug reported in discord: https://discord.com/channels/1522478522332090528/1558237749574766804

What was wrong

Editing a sentence in Docs could silently remove a video elsewhere in the document. The editor rendered raw HTML through Markdown, then parsed it into Tiptap’s supported nodes. Unsupported elements such as <video> were dropped, and autosave wrote the incomplete document back to disk. A video with a fallback link became just the link; one without fallback text disappeared entirely.

What changed

  • Preserve raw HTML blocks and inline tags in dedicated editor nodes and write their source back when saving. This includes video attributes, nested markup, and fallback links.
  • Show HTML blocks as protected source placeholders and inline tags as protected text. Raw HTML is no longer interpreted as rich content in the editor; edit the HTML itself through a source editor. The existing ::html sandboxed previews still work.
  • Document the behavior and add regression coverage using the actual video embed from my blog post.

No Plugin SDK, CLI, or wire changes.

How you verified

  • pnpm exec turbo run test typecheck lint build --filter=bb-plugin-simple-notes: all 110 tests pass; typecheck and plugin build pass; lint has no errors and eight warnings in existing code.
  • Disabled the new extensions and reran the autosave regression. It failed with the saved document containing only the heading and edited prose—the entire video embed was gone. With the extensions enabled, the same edit preserves the exact embed.
  • Added coverage for repeated save/load cycles, single-line video with a fallback link, iframes, nested HTML, comments, inert scripts and event attributes, fenced HTML code, and deleting/undoing one of multiple embeds. Existing sandboxed-preview and proposal tests pass.

Verification used the real editor in jsdom; no manual desktop/browser smoke test was performed.

AGENT GENERATED

alanagoyal and others added 10 commits October 9, 2026 17:07
Write raw HTML through the serializer's line-aware text output so blocks
inside blockquotes and list items keep their prefixes. Pair inline
formatting tags into a mark that displays the formatting and saves the
original tags; unsupported or unpaired inline HTML still shows as source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tables that cannot be written as Markdown, such as ones with a multi-line
cell, are saved as HTML. Load that HTML back as a table when it matches
the editor's own output exactly, and write inline raw HTML inside it as
attribute-carrying elements instead of visible placeholder text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tact

Tables saved as HTML now contain each inline tag's original source rather
than editor markup. An ::html directive followed by text stays a directive,
and bold or italic around an inline tag keeps its delimiters. The proposal
baseline test expects an HTML paragraph block to show as source again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le checks

Inline tag pairing now runs in linear time per paragraph and leaves
mis-nested tags as source. Pasted HTML no longer carries hidden original
tags into the document. Each HTML table's editability check is cached
across parses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
HTML the editor can represent without losing anything, judged by comparing
the original with the editor's rendering after ignoring whitespace and
Tiptap's table defaults, now displays as normal content. Other HTML blocks
become editable source blocks, other inline tags become editable inline
source, and <br> stays a line break. Source is saved exactly as typed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
HTML now displays as normal content only when saving it as Markdown and
reloading reproduces it, so images in table cells, pipes in cell code,
and similar cases stay as source instead of losing content. Internal
markers carry a per-page random value, so marker-like text in files or
pasted content stays plain text. Tags wrapping only whitespace stay as
source, and the lossless cache is kept per editor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
randomUUID exists only in secure contexts, so Docs would fail to load when
bb is opened over plain HTTP on a LAN address. getRandomValues works in
every context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous bound also timed jsdom building twenty thousand elements,
which exceeded it on the Windows runner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@brsbl

brsbl commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Moved to a stack: #5442 → #5443 → #5444 (stack #5445). #5442 contains Alana's commit d63b669 unchanged, with her description, and credits her as co-author on merge. #5443 and #5444 carry the changes below, split into HTML blocks and inline HTML. This PR is closed as superseded.

Changes from review (@brsbl)

@alanagoyal's commit d63b669 is unchanged. These commits sit on top of it. Head: 84c74cc0f · CI passed.

What changed after the original commit

  • HTML is never dropped and never locked in the editor.
  • HTML displays as normal content only when saving it as Markdown and reloading reproduces it exactly.
  • Other HTML blocks are editable source blocks labelled HTML, saved exactly as typed.
  • HTML blocks inside blockquotes and lists keep their > prefixes and indentation on save.
  • Inline formatting tags like <strong>, <kbd>, <sub>, and <a> display as formatting and keep their exact source.
  • Other inline tags, such as <video>, are editable inline source; <br> stays a line break.
  • Tables Docs must save as HTML stay editable and keep their inline HTML's original source.
  • An ::html directive followed by text stays a directive.
  • Internal markers carry a per-page random value, so marker-like text in files or pastes stays plain text.

Verification

  • Remote CI passed on 84c74cc0f.
  • Browser QA on 11851ab10 (Chrome for Testing 155, source web app) passed with no console errors; later commits change no layout.
  • Editing prose changed only that line on disk; typing inside an HTML source block saved exactly that edit.
  • A Slop Cop review of 11851ab10 found four blocking issues; 80e5ef0d0 fixes them with regression tests.
Screen / state Viewport Before (32e2aa4e8) After (11851ab10)
Doc with video embeds / opened Desktop · 1440×900 Before: video embeds missing After: video embeds shown as editable HTML source
Doc with video embeds / opened Mobile · 390×844 Before on mobile: video embeds missing After on mobile: video embeds shown as editable HTML source
Known limitations and follow-ups
  • A <span> around a link or inline code is split or moved on save; the text survives.
  • Bare <img> blocks stay as source because Tiptap's image serializer joins the next paragraph.
  • Adjacent identical tags merge, e.g. <kbd>Ctrl</kbd><kbd>C</kbd> becomes one <kbd>.
  • Runs of whitespace inside an inline HTML tag collapse to one space on save.
  • Follow-up: render HTML source blocks as a live sandboxed preview.
  • Follow-up: an HTML block that starts a list item moves out of the list on save.
  • Follow-up: an ::html line inside an HTML block is saved as the internal placeholder.
  • Follow-up: the Tasks editor still drops unsupported HTML the same way.

BB-Thread-ID: thr_fashr87x6y

AGENT GENERATED

@brsbl

brsbl commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks @alanagoyal! To review this in pieces, I moved it into a stack: #5442 (your commit, unchanged, with your description) → #5443 (HTML blocks) → #5444 (inline HTML). Squash-merging #5442 credits you as co-author. Closing this one as superseded; the comment above summarizes what changed.

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