File tree Expand file tree Collapse file tree 4 files changed +32
-0
lines changed
Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -38,5 +38,6 @@ export * from "./noteflight";
3838export * from "./reddit" ;
3939export * from "./twitter" ;
4040export * from "./vimeo" ;
41+ export * from "./whimsical" ;
4142export * from "./youtube" ;
4243export * from "./generic-preview" ;
Original file line number Diff line number Diff line change 1+ import { EmbedSource , EnableEmbedKey } from './' ;
2+
3+ const WHIMSICAL_LINK = new RegExp (
4+ / h t t p s : \/ \/ w h i m s i c a l .c o m \/ (?: [ a - z A - Z 0 - 9 \- ] + \- ) ? (?< id > [ a - k m - z A - H J - N P - Z 1 - 9 ] { 16 , 22 } ) ( @ [ a - k m - z A - H J - N P - Z 1 - 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+ }
Original file line number Diff line number Diff 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" ;
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments