feat(render): support iframe tag (#4096)

* feat: add iframe renderer support

* feat: add iframe renderer support
This commit is contained in:
pseudoyu 2025-07-07 17:44:48 +08:00 committed by GitHub
parent 44cbb984a5
commit 4edb260e04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 0 deletions

View File

@ -2,6 +2,8 @@
## Shiny new things
- Add iframe renderer support
## Improvements
## No longer broken

View File

@ -125,6 +125,25 @@ export const parseHtml = (
}
return createElement("input", props)
},
iframe: ({ node, ...props }) => {
const { width, height, src, ...rest } = props
// Apply security sandbox attributes and responsive styling
return createElement("iframe", {
...rest,
src,
width: width || "100%",
height: height || "315",
className: "max-w-full rounded",
sandbox: "allow-scripts allow-same-origin allow-popups allow-forms",
allowFullScreen: true,
loading: "lazy",
style: {
aspectRatio: width && height ? `${width} / ${height}` : "16 / 9",
...rest.style,
},
})
},
pre: ({ node, ...props }) => {
if (!props.children) return null

View File

@ -59,6 +59,7 @@ export const parseHtml = (content: string, options?: ParseHtmlOptions) => {
rehypeSchema.tagNames = [
...rehypeSchema.tagNames!,
"video",
"iframe",
"style",
"figure",
// SVG
@ -80,6 +81,18 @@ export const parseHtml = (content: string, options?: ParseHtmlOptions) => {
? [...rehypeSchema.attributes!["*"]!, "style", "class"]
: rehypeSchema.attributes!["*"]!,
video: ["src", "poster"],
iframe: [
"src",
"width",
"height",
"frameborder",
"allowfullscreen",
"sandbox",
"loading",
"title",
"id",
"class",
],
source: ["src", "type"],
svg: [