Skip to content

Commit 8547de7

Browse files
authored
Merge pull request samwarnick#58 from toddmoy/whimsical
Initial support of Whimsical Boards
2 parents b74f2c4 + f9c7036 commit 8547de7

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

embeds/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ export * from "./noteflight";
3838
export * from "./reddit";
3939
export * from "./twitter";
4040
export * from "./vimeo";
41+
export * from "./whimsical";
4142
export * from "./youtube";
4243
export * from "./generic-preview";

embeds/whimsical.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { EmbedSource, EnableEmbedKey } from './';
2+
3+
const WHIMSICAL_LINK = new RegExp(
4+
/https:\/\/whimsical.com\/(?:[a-zA-Z0-9\-]+\-)?(?<id>[a-km-zA-HJ-NP-Z1-9]{16,22})(@[a-km-zA-HJ-NP-Z1-9]+)?/
5+
);
6+
7+
export class WhimsicalEmbed implements EmbedSource {
8+
name = 'Whimsical';
9+
enabledKey: EnableEmbedKey = 'replaceWhimsicalLinks';
10+
regex = WHIMSICAL_LINK;
11+
12+
createEmbed(link: string, container: HTMLElement) {
13+
const iframe = document.createElement('iframe');
14+
15+
const matches = link.match(WHIMSICAL_LINK);
16+
const id = matches.groups.id;
17+
18+
iframe.src = `https://whimsical.com/embed/${id}`;
19+
iframe.style.aspectRatio = '800/450';
20+
iframe.style.width = '100%';
21+
iframe.setAttribute('frameborder', '0');
22+
iframe.allow = 'fullscreen';
23+
container.appendChild(iframe);
24+
container.classList.add('whimsical');
25+
return container;
26+
}
27+
}

main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
RedditEmbed,
1313
TwitterEmbed,
1414
VimeoEmbed,
15+
WhimsicalEmbed,
1516
YouTubeEmbed,
1617
GenericPreviewEmbed,
1718
} from "./embeds";
@@ -40,6 +41,7 @@ export default class SimpleEmbedsPlugin extends Plugin {
4041
new BandcampEmbed(),
4142
new VimeoEmbed(),
4243
new RedditEmbed(),
44+
new WhimsicalEmbed(),
4345
];
4446
processedMarkdown: Debouncer<[]>;
4547
currentTheme: "dark" | "light";

settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface EnableEmbeds {
1111
replaceRedditLinks: boolean;
1212
replaceTwitterLinks: boolean;
1313
replaceVimeoLinks: boolean;
14+
replaceWhimsicalLinks: boolean;
1415
replaceYouTubeLinks: boolean;
1516
replaceGenericLinks: boolean;
1617
}
@@ -69,6 +70,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
6970
replaceRedditLinks: true,
7071
replaceTwitterLinks: true,
7172
replaceVimeoLinks: true,
73+
replaceWhimsicalLinks: true,
7274
replaceYouTubeLinks: true,
7375

7476
replaceGenericLinks: false,

0 commit comments

Comments
 (0)