mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-24 17:26:10 +01:00
This commit is contained in:
parent
be3ac44ce7
commit
5025b8102c
4 changed files with 0 additions and 84 deletions
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue