diff --git a/src/embed-widget.ts b/src/embed-widget.ts index 20b6b19..dc2a86b 100644 --- a/src/embed-widget.ts +++ b/src/embed-widget.ts @@ -14,7 +14,7 @@ export class EmbedWidget extends WidgetType { } toDOM(view: EditorView): HTMLElement { - const embed = this.embedData.embedSource.createEmbed(this.url); + const embed = this.embedData.embedSource.createEmbed(this.url, this.embedData); this.embedData.embedSource.applyModifications(embed, this.embedData); return embed; } diff --git a/src/embeds/defaultFallbackEmbed.ts b/src/embeds/defaultFallbackEmbed.ts index dc60538..31b6cc6 100644 --- a/src/embeds/defaultFallbackEmbed.ts +++ b/src/embeds/defaultFallbackEmbed.ts @@ -1,11 +1,11 @@ import { FallbackOptions } from "src/settings-tab"; -import { EmbedBase } from "./embedBase"; +import { BaseEmbedData, EmbedBase } from "./embedBase"; export class DefaultFallbackEmbed extends EmbedBase { name = "Fallback Embed"; regex = new RegExp(/ /); // Not using regex for this - createEmbed(url: string): HTMLElement { + createEmbed(url: string, embedOptions: BaseEmbedData): HTMLElement { // const youtubeMatch = url.match(/https:\/\/www.youtube.com\/embed\/(\w+)/); // console.log("Match : " + youtubeMatch) // if (youtubeMatch) @@ -40,7 +40,7 @@ export class DefaultFallbackEmbed extends EmbedBase { embedContainer.appendChild(iframe); if (this.plugin.settings.fallbackAddLink) { - const link = createEl("a", {href: iframe.src, text: "Link"}); + const link = createEl("a", {href: iframe.src, text: embedOptions.alt}); embedContainer.appendChild(link); } diff --git a/src/embeds/embedBase.ts b/src/embeds/embedBase.ts index a38b0dd..3563a08 100644 --- a/src/embeds/embedBase.ts +++ b/src/embeds/embedBase.ts @@ -5,6 +5,7 @@ export class BaseEmbedData { // TODO: Add url originalString?: string; shouldEmbed: boolean; + alt?: string; width?: string; height?: string; @@ -30,7 +31,7 @@ export abstract class EmbedBase { this.plugin = plugin; } - abstract createEmbed(link: string): HTMLElement; + abstract createEmbed(link: string, embedData?: BaseEmbedData): HTMLElement; getOptions(alt: string): BaseEmbedData { const options: BaseEmbedData = new BaseEmbedData(this, alt); @@ -47,17 +48,23 @@ export abstract class EmbedBase { options.shouldEmbed = true; } + options.alt = alt; + // TODO Options: // - Size: Set both height and width at the same time. [size:100x200] // TODO: Optimise this? If there are alot of options, it might be slow. const widthMatch = alt.match(/(?:w|width)\s*(?::|=)\s*(\d+(?:%|\w+))/); - if (widthMatch) + if (widthMatch) { options.width = widthMatch[1]; + options.alt = options.alt.replace(widthMatch[0], ""); + } const heightMatch = alt.match(/(?:h|height)\s*(?::|=)\s*(\d+(?:%|\w+))/); - if (heightMatch) + if (heightMatch) { options.height = heightMatch[1]; + options.alt = options.alt.replace(heightMatch[0], ""); + } return options; } diff --git a/src/main.ts b/src/main.ts index 2b510a8..30b7220 100644 --- a/src/main.ts +++ b/src/main.ts @@ -172,7 +172,7 @@ export default class AutoEmbedPlugin extends Plugin { if (embedData === null) { return null; } - const embed = embedData.embedSource.createEmbed(src); + const embed = embedData.embedSource.createEmbed(src, embedData); embedData.embedSource.applyModifications(embed, embedData); // Insert embed diff --git a/src/settings-tab.ts b/src/settings-tab.ts index 9e4afce..5efc2bd 100644 --- a/src/settings-tab.ts +++ b/src/settings-tab.ts @@ -44,7 +44,7 @@ export const DEFAULT_SETTINGS: PluginSettings = { fallbackOptions: FallbackOptions.ShowErrorMessage, fallbackWidth: "100%", - fallbackHeight: "", + fallbackHeight: "500px", fallbackAddLink: true, showAdvancedSettings: false,