Skip to content

Commit 5ed29da

Browse files
committed
Merge branch 'live-generic-preview' into main
2 parents be26e96 + 5e8766e commit 5ed29da

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

view-plugin.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ViewUpdate,
88
WidgetType,
99
} from "@codemirror/view";
10+
import { Platform } from "obsidian";
1011
import { EmbedSource } from "./embeds";
1112
import SimpleEmbedsPlugin from "./main";
1213

@@ -114,6 +115,11 @@ export function buildSimpleEmbedsViewPlugin(plugin: SimpleEmbedsPlugin) {
114115
source.regex.test(line.text)
115116
);
116117
});
118+
119+
if (!embedSource && Platform.isDesktopApp && plugin.settings.replaceGenericLinks) {
120+
embedSource = plugin.genericPreviewEmbed;
121+
}
122+
117123
const isWithinText = this.isWithinText(text);
118124
const replaceWithEmbed = plugin.shouldReplaceWithEmbed(
119125
mdLink,
@@ -122,7 +128,17 @@ export function buildSimpleEmbedsViewPlugin(plugin: SimpleEmbedsPlugin) {
122128
const fullWidth = mdLink.includes("|fullwidth");
123129
definitions.push(...this.hideOptions(mdLink, start));
124130
if (embedSource && replaceWithEmbed) {
125-
const link = line.text.match(embedSource.regex).first();
131+
let link;
132+
133+
if (embedSource == plugin.genericPreviewEmbed) {
134+
const mdLinkRegex = /^\[([\w\s\d]+)\]\((https?:\/\/[\w\d./?=#]+)\)$/;
135+
const [_full, _text, url] = line.text.match(mdLinkRegex);
136+
if (!url) continue;
137+
link = url;
138+
}
139+
else {
140+
link = line.text.match(embedSource.regex).first();
141+
}
126142

127143
definitions.push(
128144
this.createWidget(link, fullWidth, embedSource, start, end),

0 commit comments

Comments
 (0)