Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/15128

Vanessaec34ecac5282
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index 027d620456..7d6eed7245 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -777,50 +777,42 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme
if (Array.isArray(value)) {
newValue = oldValue.mAsset.concat(value);
} else if (typeof value !== "undefined" && typeof value !== "object") { // 不传入为删除,传入字符串不进行处理
+ const htmlValue: IAVCellAssetValue[] = [];
let link = protyle.lute.GetLinkDest(value);
let name = "";
- let imgSrc = "";
// https://github.com/siyuan-note/siyuan/issues/13892
if (!link && value.startsWith("assets/")) {
link = value;
name = getAssetName(value) + pathPosix().extname(value);
}
- if (html) {
- const tempElement = document.createElement("template");
- tempElement.innerHTML = html;
- const aElement = tempElement.content.querySelector('[data-type~="a"]');
- if (aElement) {
- link = aElement.getAttribute("data-href");
- name = aElement.textContent;
- } else {
- const imgElement = tempElement.content.querySelector(".img img");
- if (imgElement) {
- imgSrc = imgElement.getAttribute("data-src");
- }
- }
- }
// https://github.com/siyuan-note/siyuan/issues/12308
- if (!link) {
- name = value;
- }
- if (!link && !name && !imgSrc) {
- break;
- }
- if (imgSrc) {
- // 支持解析 ![]() https://github.com/siyuan-note/siyuan/issues/11487
- newValue = oldValue.mAsset.concat({
- type: "image",
- content: imgSrc,
- name: ""
- });
- } else {
- // 支持解析 https://github.com/siyuan-note/siyuan/issues/11463
- newValue = oldValue.mAsset.concat({
+ if (link) {
+ htmlValue.push({
type: "file",
content: link,
name
});
}
+ if (html) {
+ const tempElement = document.createElement("template");
+ tempElement.innerHTML = html;
+ tempElement.content.querySelectorAll('[data-type~="a"], .img img').forEach(item => {
+ if (item.tagName === "IMG") {
+ htmlValue.push({
+ type: "image",
+ content: item.getAttribute("data-src"),
+ name: ""
+ });
+ } else {
+ htmlValue.push({
+ type: "file",
+ content: item.getAttribute("data-href"),
+ name: item.textContent
+ });
+ }
+ });
+ }
+ newValue = oldValue.mAsset.concat(htmlValue);
}
} else if (type === "mSelect" || type === "select") {
// 不传入为删除
diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts
index d7e19a1a2f..c9843a06eb 100644
--- a/app/src/protyle/util/insertHTML.ts
+++ b/app/src/protyle/util/insertHTML.ts
@@ -188,7 +188,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
break;
}
const cellValue = textJSON[i][j];
- const operations = await updateCellsValue(protyle, blockElement as HTMLElement, cellValue, [cellElement], columns, html, true);
+ const operations = await updateCellsValue(protyle, blockElement as HTMLElement, cellValue, [cellElement], columns, tempElement.content.children[i].outerHTML, true);
if (operations.doOperations.length > 0) {
doOperations.push(...operations.doOperations);
undoOperations.push(...operations.undoOperations);
@@ -292,10 +292,13 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
return;
}
- if (blockElement.classList.contains("av") && !isBlock) {
- range.deleteContents();
- processAV(range, html, protyle, blockElement as HTMLElement);
- return;
+ if (blockElement.classList.contains("av")) {
+ const avTitleElement = hasClosestByClassName(range.startContainer, "av__title");
+ if (!avTitleElement || (avTitleElement && !isBlock)) {
+ range.deleteContents();
+ processAV(range, html, protyle, blockElement as HTMLElement);
+ return;
+ }
}
if (blockElement.classList.contains("table") && blockElement.querySelector(".table__select").clientWidth > 0 &&
processTable(range, html, protyle, blockElement)) {