Skip to content

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

:bug: Preserve database rich-text list markers https://github.com/siyuan-note/siyuan/issues/11553

Daniel69f9a8250ed1
diff --git a/app/src/protyle/render/av/richText.test.ts b/app/src/protyle/render/av/richText.test.ts
index abfc30dc65..8dfaf2fd8a 100644
--- a/app/src/protyle/render/av/richText.test.ts
+++ b/app/src/protyle/render/av/richText.test.ts
@@ -17,6 +17,7 @@ import {
getAVTextPlainContent,
getAVTextSource,
getAVRichTextSafeURL,
+ isAVRichTextEditorAllowedTag,
isAVRichTextExecutableCodeLanguage,
projectAVRichTextPlainBlocks,
protectAVRichTextKramdownStyleEntities,
@@ -287,6 +288,10 @@ describe("attribute view text source compatibility", () => {
});
it("uses a strict active-content and interaction policy for previews", () => {
+ for (const tag of ["svg", "SVG", "use", "USE"]) {
+ assert.equal(isAVRichTextEditorAllowedTag(tag), true);
+ }
+ assert.equal(isAVRichTextEditorAllowedTag("script"), false);
for (const tag of ["h1", "h2", "h3", "h4", "h5", "h6"]) {
assert.equal(AV_RICH_TEXT_PREVIEW_ALLOWED_TAGS.includes(tag), true);
}
diff --git a/app/src/protyle/render/av/richText.ts b/app/src/protyle/render/av/richText.ts
index 3d2d6da7d2..5c850a055d 100644
--- a/app/src/protyle/render/av/richText.ts
+++ b/app/src/protyle/render/av/richText.ts
@@ -7,6 +7,7 @@ import {
createAVRichTextStyleEntityReplacer,
configureAVRichTextLute,
getAVRichTextSafeURL,
+ isAVRichTextEditorAllowedTag,
isAVRichTextExecutableCodeLanguage,
projectAVRichTextPlainBlocks,
protectAVRichTextKramdownStyleEntities,
@@ -15,7 +16,6 @@ import {
AV_RICH_TEXT_PREVIEW_SANITIZE_OPTIONS,
AV_RICH_TEXT_PREVIEW_TEXT_ONLY_TAGS,
AV_RICH_TEXT_EDITOR_ALLOWED_ATTRIBUTES,
- AV_RICH_TEXT_EDITOR_ALLOWED_TAGS,
} from "./richTextValue";
import type {AVRichTextStyleEntityProtection} from "./richTextValue";
@@ -74,7 +74,6 @@ const ALLOWED_INLINE_TYPES = new Set([
"text",
"u",
]);
-const ALLOWED_EDITOR_TAGS = new Set(AV_RICH_TEXT_EDITOR_ALLOWED_TAGS.map((tag) => tag.toUpperCase()));
const previewCache = new Map<string, string>();
const PREVIEW_CACHE_LIMIT = 256;
let richTextLute: Lute | undefined;
@@ -138,7 +137,7 @@ export const sanitizeAVRichTextBlockDOM = (blockDOM: string) => {
element.remove();
});
template.content.querySelectorAll<HTMLElement>("*").forEach((element) => {
- if (!ALLOWED_EDITOR_TAGS.has(element.tagName)) {
+ if (!isAVRichTextEditorAllowedTag(element.tagName)) {
replaceWithText(element);
}
});
diff --git a/app/src/protyle/render/av/richTextValue.ts b/app/src/protyle/render/av/richTextValue.ts
index 8b62f99f34..9ab6d88190 100644
--- a/app/src/protyle/render/av/richTextValue.ts
+++ b/app/src/protyle/render/av/richTextValue.ts
@@ -12,6 +12,9 @@ export const AV_RICH_TEXT_PREVIEW_ALLOWED_ATTRIBUTES = [
];
export const AV_RICH_TEXT_PREVIEW_TEXT_ONLY_TAGS = ["sup"];
export const AV_RICH_TEXT_EDITOR_ALLOWED_TAGS = ["br", "div", "span", "svg", "use", "wbr"];
+const AV_RICH_TEXT_EDITOR_ALLOWED_TAG_SET = new Set(AV_RICH_TEXT_EDITOR_ALLOWED_TAGS);
+export const isAVRichTextEditorAllowedTag = (tagName: string) =>
+ AV_RICH_TEXT_EDITOR_ALLOWED_TAG_SET.has(tagName.toLowerCase());
export const AV_RICH_TEXT_EDITOR_ALLOWED_ATTRIBUTES = [
"aria-label", "class", "contenteditable", "data-content", "data-href", "data-id", "data-inline-memo-content",
"data-marker", "data-node-id", "data-node-index", "data-position", "data-subtype", "data-type", "draggable",