feat: more embed support (#560)

This commit is contained in:
Birdgg
2023-05-19 15:35:04 +01:00
committed by GitHub
parent f903699842
commit add4afcabc
13 changed files with 326 additions and 36 deletions
@@ -0,0 +1,23 @@
import type { Transformer } from "../rehype-embed"
import { generateIframeHTML, isHostIncludes } from "./utils"
export const CodeSandboxTransformer: Transformer = {
name: "CodeSandbox",
shouldTransform(url) {
const { host, pathname } = url
return isHostIncludes("codesandbox.io", host) && pathname.includes("/s/")
},
getHTML(url) {
return generateIframeHTML({
name: "codesandbox",
src: url.toString().replace("/s/", "/embed/"),
height: "500px",
width: "100%",
allow:
"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking",
sandbox:
"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts",
})
},
}