Allow adding a URL suffix to Markdown mode, closes #37

This commit is contained in:
Ell 2022-06-01 15:15:43 +02:00
parent 52c1005440
commit cd0285c2dd
3 changed files with 18 additions and 10 deletions

View file

@ -23,18 +23,14 @@ frame: YOUR FRAME'S NAME
``` ```
~~~ ~~~
Optionally, you can also pass custom style settings to the embed, which allows you to change things like the embed's height: Optionally, you can also pass custom style settings to the embed, which allows you to change things like the embed's height, as well as an additional suffix that will be appended to the frame's regular URL, which can be useful for things like displaying a specific note in Google Keep.
~~~
```custom-frames
frame: YOUR FRAME'S NAME
style: SOME CSS
~~~
Here's an example that creates a very tall embed using the [Google Keep preset](#-presets): Here's an example using the [Google Keep preset](#-presets):
~~~ ~~~
```custom-frames ```custom-frames
frame: Google Keep frame: Google Keep
style: height: 1000px; style: height: 1000px;
urlSuffix: #reminders
``` ```
~~~ ~~~

View file

@ -12,7 +12,7 @@ export class CustomFrame {
this.data = data; this.data = data;
} }
public create(additionalStyle: string = undefined): any { public create(additionalStyle: string = undefined, urlSuffix: string = undefined): any {
let style = `padding: ${this.settings.padding}px;`; let style = `padding: ${this.settings.padding}px;`;
if (additionalStyle) if (additionalStyle)
style += additionalStyle; style += additionalStyle;
@ -32,7 +32,15 @@ export class CustomFrame {
} }
this.frame.addClass("custom-frames-frame"); this.frame.addClass("custom-frames-frame");
this.frame.setAttribute("style", style); this.frame.setAttribute("style", style);
this.frame.setAttribute("src", this.data.url);
let src = this.data.url;
if (urlSuffix) {
if (!urlSuffix.startsWith("/"))
src += "/";
src += urlSuffix;
}
this.frame.setAttribute("src", src);
return this.frame; return this.frame;
} }

View file

@ -63,8 +63,12 @@ export default class CustomFramesPlugin extends Plugin {
let style = styleMatch && styleMatch[1].trim(); let style = styleMatch && styleMatch[1].trim();
style ||= "height: 600px;"; style ||= "height: 600px;";
let urlSuffixMatch = /urlsuffix:([^\n]+)/gi.exec(s);
let urlSuffix = urlSuffixMatch && urlSuffixMatch[1].trim();
urlSuffix ||= "";
let frame = new CustomFrame(this.settings, data); let frame = new CustomFrame(this.settings, data);
e.appendChild(frame.create(style)); e.appendChild(frame.create(style, urlSuffix));
}); });
} }