mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-12 10:14:21 +01:00
This commit is contained in:
parent
0e8432fd16
commit
ec34ecac52
2 changed files with 31 additions and 36 deletions
|
|
@ -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") {
|
||||
// 不传入为删除
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue