Rich text: iframe embeds are lost when an entry is saved from the visual editor

Open
#482 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start with src/components/ui/editor/html-policy.ts and trace how forbiddenTags, parseMarkdown, and sourceMarkdown handle iframe blocks. Reproduce the reported save flow with a Markdown file containing an iframe, then check whether the saved content preserves it byte for byte without rendering it in the visual editor. The issue names no test files, so locate the relevant editor tests and add coverage for this case.

Written by the indexing model from the issue text.

Description

Problem

The visual rich-text editor removes iframes, and nothing in options.html can allow them. If an entry with an embed (YouTube, Vimeo, Bunny, maps) is opened in the visual editor and saved, the embed is removed from the file. Nothing tells the editor it's been removed.

Many existing sites have embeds in Markdown or HTML content, so this can lose content on otherwise ordinary edits. It worked in 2.x on my fork, where unsupported HTML was kept as a block and written back unchanged.

Steps to reproduce
  1. Add a Markdown file with an embed:

    Intro text.
    
    <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" title="Video" allowfullscreen></iframe>
    
    More text.
    
  2. Open it in a rich-text field (default Markdown format).

  3. Edit "Intro text" in the visual editor and save.

Expected: the iframe is kept.
Actual: the iframe is removed from the saved file.

Cause

In src/components/ui/editor/html-policy.ts:

  • iframe is in forbiddenTags, so sanitizing the block leaves nothing, and parseMarkdown returns an omitted node. That node is written back as an empty string.
  • Wrapping the embed so it's kept as a source block doesn't help: sourceMarkdown saves source that contains a forbidden tag as a fenced code block.
Suggestion

Keep forbidden HTML in the document instead of dropping it:

  1. Treat a block with forbidden tags as a read-only source block. Show it as code, never render it in the editor, and write it back byte for byte.
  2. Optionally, add an allowlist such as options.html.embeds: [youtube.com, player.vimeo.com] so the editor can show a sandboxed preview of trusted embeds.

Option 1 alone would prevent the data loss without any risk in the editor, since the HTML is never rendered there.

Workaround

Editing in Source mode keeps the iframe. A shortcode such as {% youtube "id" %} with options.preserve avoids raw HTML altogether.

Version

3.0.1, self-hosted on Cloudflare Workers.

Dominant language
TypeScript
Stars
4.1k
Forks
564
Avg merge
8m
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hunvreus/pagescms

All issues in hunvreus/pagescms

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.