An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve table cell soft breaks when typing and pasting https://github.com/siyuan-note/siyuan/issues/19188
Daniel4068d266d83a
diff --git a/app/src/protyle/render/tableCellRichEditor.ts b/app/src/protyle/render/tableCellRichEditor.tsindex 8294e3aa5d..45ee619fc1 100644--- a/app/src/protyle/render/tableCellRichEditor.ts+++ b/app/src/protyle/render/tableCellRichEditor.ts@@ -20,6 +20,7 @@ import {TABLE_CELL_SLASH_IDS} from "../util/tableCellRichMenu";import {captureRichCellSelection, restoreRichCellSelection} from "../util/tableCellRichSelection";import {matchHotKey} from "../util/hotKey";import {bindTableCellRichDrag} from "../util/tableCellRichDrag";+import {getTableCellEditorLute} from "../util/tableCellRichLute";let activeEditor: {cell: Element, finish: () => void} | undefined;@@ -39,7 +40,7 @@ export const applyTableCellRichInlineMark = (owner: IProtyle, cells: HTMLTableCeapp: owner.app,runtimeCapabilities: {upload: false, websocket: false, pluginExtensions: false, customBlockRender: false,- lute: getAVRichTextLute(),+ lute: getTableCellEditorLute(getAVRichTextLute()),sanitizeBlockDOM: html => sanitizeAVRichTextBlockDOM(html, true),getUnsupportedPasteBlocks: html => getAVRichTextUnsupportedPasteBlocks(html, true),restoreLuteMarkdownSyntax: configureAVRichTextLute,@@ -144,7 +145,7 @@ export const openTableCellRichEditor = (owner: IProtyle, cell: HTMLTableCellElemwebsocket: false,pluginExtensions: false,customBlockRender: false,- lute: getAVRichTextLute(),+ lute: getTableCellEditorLute(getAVRichTextLute()),lockedOptions: {toolbar, hint},sanitizeBlockDOM: html => sanitizeAVRichTextBlockDOM(html, true),getUnsupportedPasteBlocks: html => getAVRichTextUnsupportedPasteBlocks(html, true),diff --git a/app/src/protyle/util/tableCellRichLute.ts b/app/src/protyle/util/tableCellRichLute.tsnew file mode 100644index 0000000000..485c023f21--- /dev/null+++ b/app/src/protyle/util/tableCellRichLute.ts@@ -0,0 +1,26 @@+// 单元格内的软换行属于行内内容,重新解析时不能作为 Markdown 段落分隔符。+export const getTableCellEditorLute = (lute: Lute): Lute => new Proxy(lute, {+ get(target, property) {+ if (property !== "SpinBlockDOM") {+ return Reflect.get(target, property);+ }+ return (html: string) => {+ const template = document.createElement("template");+ template.innerHTML = html;+ let token = "SYTABLECELLSOFTBREAK";+ while (html.includes(token)) {+ token += "X";+ }+ const walker = document.createTreeWalker(template.content, NodeFilter.SHOW_TEXT);+ let node: Node;+ while ((node = walker.nextNode())) {+ const element = node.parentElement;+ if (element?.closest('[contenteditable="true"]') &&+ !element.closest('[data-type="NodeCodeBlock"], [data-type="NodeMathBlock"], .img')) {+ node.textContent = node.textContent.replace(/\n/g, token);+ }+ }+ return target.SpinBlockDOM(template.innerHTML).split(token).join(" ");+ };+ },+});