Vanessa 2024-05-22 22:56:06 +08:00
parent 8479aef270
commit 17e77274fa
2 changed files with 10 additions and 7 deletions

View File

@ -32,13 +32,13 @@ export const initBlockPopover = (app: App) => {
} else { } else {
if (aElement.firstElementChild?.getAttribute("data-type") === "url") { if (aElement.firstElementChild?.getAttribute("data-type") === "url") {
if (aElement.firstElementChild.textContent.indexOf("...") > -1) { if (aElement.firstElementChild.textContent.indexOf("...") > -1) {
tip = aElement.firstElementChild.getAttribute("data-href"); tip = Lute.EscapeHTMLStr(aElement.firstElementChild.getAttribute("data-href"));
} }
} }
if (!tip && aElement.dataset.wrap !== "true" && event.target.dataset.type !== "block-more" && !hasClosestByClassName(event.target, "block__icon")) { if (!tip && aElement.dataset.wrap !== "true" && event.target.dataset.type !== "block-more" && !hasClosestByClassName(event.target, "block__icon")) {
aElement.style.overflow = "auto"; aElement.style.overflow = "auto";
if (aElement.scrollWidth > aElement.clientWidth + 2) { if (aElement.scrollWidth > aElement.clientWidth + 2) {
tip = getCellText(aElement); tip = Lute.EscapeHTMLStr(getCellText(aElement));
} }
aElement.style.overflow = ""; aElement.style.overflow = "";
} }

View File

@ -30,9 +30,10 @@ const renderCellURL = (urlContent: string) => {
} }
} catch (e) { } catch (e) {
// 不是 url 地址 // 不是 url 地址
host = Lute.EscapeHTMLStr(urlContent);
} }
// https://github.com/siyuan-note/siyuan/issues/9291 // https://github.com/siyuan-note/siyuan/issues/9291
return `<span class="av__celltext av__celltext--url" data-type="url" data-href="${urlContent}"><span>${host}</span><span class="ft__on-surface">${suffix}</span></span>`; return `<span class="av__celltext av__celltext--url" data-type="url" data-href="${escapeAttr(urlContent)}"><span>${host}</span><span class="ft__on-surface">${suffix}</span></span>`;
}; };
export const getCellText = (cellElement: HTMLElement | false) => { export const getCellText = (cellElement: HTMLElement | false) => {
@ -149,7 +150,7 @@ export const genCellValue = (colType: TAVCol, value: string | any) => {
cellValue = { cellValue = {
type: colType, type: colType,
[colType]: { [colType]: {
content: ["block", "text", "url", "phone", "email"].includes(colType) ? Lute.EscapeHTMLStr(value) : value content: value
} }
}; };
} else if (colType === "mSelect" || colType === "select") { } else if (colType === "mSelect" || colType === "select") {
@ -687,10 +688,12 @@ export const renderCellAttr = (cellElement: Element, value: IAVCellValue) => {
export const renderCell = (cellValue: IAVCellValue, rowIndex = 0) => { export const renderCell = (cellValue: IAVCellValue, rowIndex = 0) => {
let text = ""; let text = "";
if (["text", "template"].includes(cellValue.type)) { if ("template" === cellValue.type) {
text = `<span class="av__celltext">${cellValue ? (cellValue[cellValue.type as "text"].content || "") : ""}</span>`; text = `<span class="av__celltext">${cellValue ? (cellValue.template.content || "") : ""}</span>`;
} else if ("text" === cellValue.type) {
text = `<span class="av__celltext">${cellValue ? Lute.EscapeHTMLStr(cellValue.text.content || "") : ""}</span>`;
} else if (["email", "phone"].includes(cellValue.type)) { } else if (["email", "phone"].includes(cellValue.type)) {
text = `<span class="av__celltext av__celltext--url" data-type="${cellValue.type}">${cellValue ? cellValue[cellValue.type as "email"].content : ""}</span>`; text = `<span class="av__celltext av__celltext--url" data-type="${cellValue.type}">${cellValue ? Lute.EscapeHTMLStr(cellValue[cellValue.type as "email"].content || "") : ""}</span>`;
} else if ("url" === cellValue.type) { } else if ("url" === cellValue.type) {
text = renderCellURL(cellValue?.url?.content || ""); text = renderCellURL(cellValue?.url?.content || "");
} else if (cellValue.type === "block") { } else if (cellValue.type === "block") {