diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e00d9115..c472aec97 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -81,6 +81,7 @@ SPDX-License-Identifier: CC-BY-SA-4.0
- The email sign-in/registration does not require an email address anymore but uses a username
- The history shows both the entries saved in LocalStorage and the entries saved on the server together
- The gist embedding uses a click-shield, like vimeo and youtube
+- HTML-Iframes are capsuled in click-shields
- Use [Twemoji](https://twemoji.twitter.com/) as icon font
- The `[name=...]`, `[time=...]` and `[color=...]` tags may now be used anywhere in the document and not just inside of blockquotes and lists.
- The (add image) and (add link) toolbar buttons put selected links directly in the `()` instead of the `[]` part of the generated markdown.
diff --git a/cypress/integration/iframe-capsule.ts b/cypress/integration/iframe-capsule.ts
new file mode 100644
index 000000000..69abe4423
--- /dev/null
+++ b/cypress/integration/iframe-capsule.ts
@@ -0,0 +1,17 @@
+/*
+ * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+describe('Iframe capsule', () => {
+ beforeEach(() => {
+ cy.visitTestEditor()
+ })
+
+ it('shows a clickable click shield instead of the iframe', () => {
+ cy.setCodemirrorContent('')
+ cy.getMarkdownBody().findById('iframe-capsule-click-shield').should('exist').click()
+ cy.getMarkdownBody().find('iframe').should('exist').should('have.attr', 'src', 'https://example.org')
+ })
+})
diff --git a/src/components/markdown-renderer/hooks/use-markdown-extensions.ts b/src/components/markdown-renderer/hooks/use-markdown-extensions.ts
index b74033a7a..9b84d1a7b 100644
--- a/src/components/markdown-renderer/hooks/use-markdown-extensions.ts
+++ b/src/components/markdown-renderer/hooks/use-markdown-extensions.ts
@@ -39,6 +39,7 @@ import type { LineMarkers } from '../markdown-extension/linemarker/add-line-mark
import type { ImageClickHandler } from '../markdown-extension/image/proxy-image-replacer'
import type { TocAst } from 'markdown-it-toc-done-right'
import type { MarkdownExtension } from '../markdown-extension/markdown-extension'
+import { IframeCapsuleMarkdownExtension } from '../markdown-extension/iframe-capsule/iframe-capsule-markdown-extension'
/**
* Provides a list of {@link MarkdownExtension markdown extensions} that is a combination of the common extensions and the given additional.
@@ -73,6 +74,7 @@ export const useMarkdownExtensions = (
currentLineMarkers ? (lineMarkers) => (currentLineMarkers.current = lineMarkers) : undefined,
lineOffset
),
+ new IframeCapsuleMarkdownExtension(),
new GistMarkdownExtension(),
new YoutubeMarkdownExtension(),
new VimeoMarkdownExtension(),
diff --git a/src/components/markdown-renderer/markdown-extension/iframe-capsule/iframe-capsule-markdown-extension.ts b/src/components/markdown-renderer/markdown-extension/iframe-capsule/iframe-capsule-markdown-extension.ts
new file mode 100644
index 000000000..23bcd8a5d
--- /dev/null
+++ b/src/components/markdown-renderer/markdown-extension/iframe-capsule/iframe-capsule-markdown-extension.ts
@@ -0,0 +1,22 @@
+/*
+ * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { MarkdownExtension } from '../markdown-extension'
+import type { ComponentReplacer } from '../../replace-components/component-replacer'
+import { IframeCapsuleReplacer } from './iframe-capsule-replacer'
+
+/**
+ * Adds a replacer that capsules iframes in a click shield.
+ */
+export class IframeCapsuleMarkdownExtension extends MarkdownExtension {
+ public buildReplacers(): ComponentReplacer[] {
+ return [new IframeCapsuleReplacer()]
+ }
+
+ public buildTagNameWhitelist(): string[] {
+ return ['iframe']
+ }
+}
diff --git a/src/components/markdown-renderer/markdown-extension/iframe-capsule/iframe-capsule-replacer.tsx b/src/components/markdown-renderer/markdown-extension/iframe-capsule/iframe-capsule-replacer.tsx
new file mode 100644
index 000000000..994423a92
--- /dev/null
+++ b/src/components/markdown-renderer/markdown-extension/iframe-capsule/iframe-capsule-replacer.tsx
@@ -0,0 +1,32 @@
+/*
+ * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import type { NativeRenderer, NodeReplacement, SubNodeTransform } from '../../replace-components/component-replacer'
+import { ComponentReplacer, DO_NOT_REPLACE } from '../../replace-components/component-replacer'
+import type { Element } from 'domhandler'
+import { ClickShield } from '../../replace-components/click-shield/click-shield'
+
+/**
+ * Capsules