mirror of
https://github.com/gnoxnahte/obsidian-auto-embed.git
synced 2026-07-22 09:50:24 +00:00
23 lines
No EOL
785 B
TypeScript
23 lines
No EOL
785 B
TypeScript
import { PluginSettings } from "main";
|
|
import { EmbedBase } from "./embedBase";
|
|
|
|
export class CodepenEmbed extends EmbedBase {
|
|
name = "CodePen";
|
|
regex = new RegExp(/https:\/\/codepen\.io\/(\w+)\/pen\/(\w+)(\?.*)?/);
|
|
|
|
createEmbed(url: string, settings: Readonly<PluginSettings>): HTMLElement {
|
|
const regexMatch = url.match(this.regex);
|
|
// Shouldn't happen since got test before. But in case
|
|
if (regexMatch === null)
|
|
return this.onErrorCreatingEmbed();
|
|
|
|
// Creating the iframe
|
|
const iframe = createEl("iframe");
|
|
|
|
iframe.src = `https://codepen.io/${regexMatch[1]}/embed/${regexMatch[2]}?default-tab=result&editable=true`;
|
|
|
|
iframe.classList.add("auto-embed", "codepen-embed");
|
|
|
|
return iframe;
|
|
}
|
|
}
|