mirror of
https://github.com/gnoxnahte/obsidian-auto-embed.git
synced 2026-07-22 09:50:24 +00:00
Add alt text to default fallback bottom link
This commit is contained in:
parent
7e8c663fae
commit
fa2bb8a0ca
5 changed files with 16 additions and 9 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
|
|||
|
||||
fallbackOptions: FallbackOptions.ShowErrorMessage,
|
||||
fallbackWidth: "100%",
|
||||
fallbackHeight: "",
|
||||
fallbackHeight: "500px",
|
||||
fallbackAddLink: true,
|
||||
|
||||
showAdvancedSettings: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue