Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/6460

Vanessa5025b8102c25
diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts
index 7bb9bb9265..e8960476c0 100644
--- a/app/src/protyle/export/index.ts
+++ b/app/src/protyle/export/index.ts
@@ -516,7 +516,6 @@ const onExport = (data: IWebSocketData, filePath: string, type: string, removeAs
Protyle.mindmapRender(previewElement, "stage/protyle");
Protyle.abcRender(previewElement, "stage/protyle");
Protyle.plantumlRender(previewElement, "stage/protyle");
- Protyle.mediaRender(previewElement);
document.querySelectorAll(".protyle-action__copy").forEach((item) => {
item.addEventListener("click", (event) => {
navigator.clipboard.writeText(item.parentElement.nextElementSibling.textContent.trimEnd());
diff --git a/app/src/protyle/markdown/mediaRender.ts b/app/src/protyle/markdown/mediaRender.ts
deleted file mode 100644
index a1fb153258..0000000000
--- a/app/src/protyle/markdown/mediaRender.ts
+++ /dev/null
@@ -1,78 +0,0 @@
-const videoRender = (element: HTMLElement, url: string) => {
- element.insertAdjacentHTML("afterend", `<video controls="controls" src="${url}"></video>`);
- element.remove();
-};
-
-const audioRender = (element: HTMLElement, url: string) => {
- element.insertAdjacentHTML("afterend", `<audio controls="controls" src="${url}"></audio>`);
- element.remove();
-};
-
-const iframeRender = (element: HTMLElement, url: string) => {
- const youtubeMatch = url.match(/\/\/(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w|-]{11})(?:(?:[\?&]t=)(\S+))?/);
- const youkuMatch = url.match(/\/\/v\.youku\.com\/v_show\/id_(\w+)=*\.html/);
- const qqMatch = url.match(/\/\/v\.qq\.com\/x\/cover\/.*\/([^\/]+)\.html\??.*/);
- const coubMatch = url.match(/(?:www\.|\/\/)coub\.com\/view\/(\w+)/);
- const facebookMatch = url.match(/(?:www\.|\/\/)facebook\.com\/([^\/]+)\/videos\/([0-9]+)/);
- const dailymotionMatch = url.match(/.+dailymotion.com\/(video|hub)\/(\w+)\?/);
- const bilibiliMatch = url.match(/(?:www\.|\/\/)bilibili\.com\/video\/(\w+)/);
- const tedMatch = url.match(/(?:www\.|\/\/)ted\.com\/talks\/(\w+)/);
- const asciinemaMatch = url.match(/(?:www\.|\/\/)asciinema\.org\/a\/(\w+)/);
- if (youtubeMatch && youtubeMatch[1].length === 11) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://www.youtube.com/embed/${youtubeMatch[1] +
- (youtubeMatch[2] ? "?start=" + youtubeMatch[2] : "")}"></iframe>`);
- element.remove();
- } else if (youkuMatch && youkuMatch[1]) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://player.youku.com/embed/${youkuMatch[1]}"></iframe>`);
- element.remove();
- } else if (qqMatch && qqMatch[1]) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://v.qq.com/txp/iframe/player.html?vid=${qqMatch[1]}"></iframe>`);
- element.remove();
- } else if (coubMatch && coubMatch[1]) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://coub.com/embed/${coubMatch[1]}?muted=false&autostart=false&originalSize=true&startWithHD=true"></iframe>`);
- element.remove();
- } else if (facebookMatch && facebookMatch[0]) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://www.facebook.com/plugins/video.php?href=${encodeURIComponent(facebookMatch[0])}"></iframe>`);
- element.remove();
- } else if (dailymotionMatch && dailymotionMatch[2]) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://www.dailymotion.com/embed/video/${dailymotionMatch[2]}"></iframe>`);
- element.remove();
- } else if (bilibiliMatch && bilibiliMatch[1]) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://player.bilibili.com/player.html?bvid=${bilibiliMatch[1]}"></iframe>`);
- element.remove();
- } else if (tedMatch && tedMatch[1]) {
- element.insertAdjacentHTML("afterend",
- `<iframe src="https://embed.ted.com/talks/${tedMatch[1]}"></iframe>`);
- element.remove();
- } else if (asciinemaMatch && asciinemaMatch[1]) {
- element.insertAdjacentHTML("afterend",
- `<iframe style="height: 462px;width: 737px;min-width: auto;" src="https://asciinema.org/a/${asciinemaMatch[1]}/embed?"></iframe>`);
- element.remove();
- }
-};
-
-export const mediaRender = (element: HTMLElement) => {
- if (!element) {
- return;
- }
- element.querySelectorAll("a").forEach((aElement) => {
- const url = aElement.getAttribute("href");
- if (!url) {
- return;
- }
- if (url.match(/^.+.(mp4|m4v|ogg|ogv|webm)$/)) {
- videoRender(aElement, url);
- } else if (url.match(/^.+.(mp3|wav|flac)$/)) {
- audioRender(aElement, url);
- } else {
- iframeRender(aElement, url);
- }
- });
-};
diff --git a/app/src/protyle/method.ts b/app/src/protyle/method.ts
index 51ee1a1d72..c73677e6e2 100644
--- a/app/src/protyle/method.ts
+++ b/app/src/protyle/method.ts
@@ -6,7 +6,6 @@ import { flowchartRender } from "./markdown/flowchartRender";
import { chartRender } from "./markdown/chartRender";
import { abcRender } from "./markdown/abcRender";
import { mindmapRender } from "./markdown/mindmapRender";
-import { mediaRender } from "./markdown/mediaRender";
import { plantumlRender } from "./markdown/plantumlRender";
import "../assets/scss/export.scss";
@@ -30,8 +29,6 @@ class Protyle {
public static mindmapRender = mindmapRender;
/** UML 渲染 */
public static plantumlRender = plantumlRender;
- /** 为[特定链接](https://github.com/Vanessa219/vditor/issues/7)分别渲染为视频、音频、嵌入的 iframe */
- public static mediaRender = mediaRender;
}
export default Protyle;
diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.ts
index 449d3ef7b8..076f0e1d52 100644
--- a/app/src/protyle/preview/index.ts
+++ b/app/src/protyle/preview/index.ts
@@ -17,7 +17,6 @@ import {fetchPost} from "../../util/fetch";
import {processRender} from "../util/processCode";
import {highlightRender} from "../markdown/highlightRender";
import {speechRender} from "../markdown/speechRender";
-import {mediaRender} from "../markdown/mediaRender";
export class Preview {
public element: HTMLElement;
@@ -165,7 +164,6 @@ export class Preview {
processRender(protyle.preview.previewElement);
highlightRender(protyle.preview.previewElement);
speechRender(protyle.preview.previewElement, protyle.options.lang);
- mediaRender(protyle.preview.previewElement);
});
}, protyle.options.preview.delay);
}