datahub/packages/remark-embed/src/lib/remark-embed.ts
Ola Rubaj af134cac8b
Integrate flowershow packages (#923)
* [packages][m]: mv @flowershow/core package here

* [packages/core][xs]: rename to @portaljs/core

* [package.json][xs]: setup npm workspaces

* [packages/core][xs]:replace deprecated rollup executor

* [core/package.json][s]: fix mermaid versions

* [core/tsconfig][xs]: rm extends

* [core/jest.config][xs]: rm coverageDirectory

* [core/package.json][xs]: install core-js

* [packages.json][s]:use same version for all nrwl packages

* [core/.eslintrc][xs]: adjust ignorePatterns

* [core/project.json][xs]: rm publish targets

* [packages][m]: mv @flowershow/remark-wiki-link here

* [packages][m]: mv @flowershow/remark-wiki-link here

* [packages][m]: mv @flowershow/remark-embed here

* [remark-callouts/project.json][xs]: adjst test pattern

* [package.json][s]: install missing deps

* [remark-callouts][xs]: adjst fields in package.json

* [remark-callouts][s]: rm pubish targets and adjst build executor

* [remark-embed/jest.config][xs]: rm unknown option coverageDirectory

* [remark-embed][xs]: rm publish targets

* [remark-embed][s]: rename to @portaljs/remark-embed

* [remark-wiki-link/eslintrc][xs]:adjst ignorePatterns

* [package.json][xs]: install missing deps

* [remark-wiki-link/test][xs]:specify format

- also temporarily force any type on htmlExtension

* [remark-wiki-link/README][xs]: replace @flowershow with @portaljs

* [remark-wiki-link][xs]:rm old changelog

* [remark-wiki-link][xs]: adjst package.json

* [remark-wiki-link/project.json][xs]: rm publish targets

* [core][s]: rm old changelog

* [core/README][xs]:correct scope name

* [remark-callouts/README][xs]: add @portaljs to pckg name

* [remark-embed/README][xs]: add @portaljs to pckg name

* [package-lock.json][xs]: refresh after rebasing on main
2023-06-07 07:21:00 -03:00

50 lines
1.3 KiB
TypeScript

import { visit } from "unist-util-visit";
function transformer(tree) {
visit(tree, "paragraph", (node) => {
visit(node, "text", (textNode) => {
if (
textNode.value.includes("https://www.youtube.com") &&
!textNode.value.includes("\n")
) {
const urlSplit = textNode.value.split(/[=&]+/);
const iframeUrl = `https://www.youtube.com/embed/${urlSplit[1]}`;
Object.assign(node, {
...node,
type: "element",
data: {
hProperties: {
style: "position:relative;padding-bottom:56.25%",
},
},
children: [
{
...textNode,
type: "element",
tagName: "iframe",
data: {
hName: "iframe",
hProperties: {
style:
"position:absolute;top:0;left:0;width:100%;height:100%",
src: iframeUrl,
allowfullscreen: true,
frameborder: "0",
allow:
"accelerometer autoplay clipboard-write encrypted-media gyroscope picture-in-picture",
},
},
},
],
});
}
});
});
}
function attacher() {
return transformer;
}
export default attacher;