katex parse

This commit is contained in:
2025-12-01 21:11:34 +08:00
parent fa660200fd
commit f01076c3e6
5 changed files with 52 additions and 12 deletions

View File

@@ -386,6 +386,7 @@ function parseRichTexts(raw: any): RichText[] {
let href: string | undefined
let mentionPageId: string | undefined
let equationExpression: string | undefined
if (Array.isArray(decorations)) {
for (const deco of decorations) {
@@ -418,6 +419,16 @@ function parseRichTexts(raw: any): RichText[] {
mentionPageId =
typeof value === 'object' && value?.id ? value.id : undefined
break
case 'e': {
if (typeof value === 'string') {
equationExpression = value
} else if (Array.isArray(value) && typeof value[0] === 'string') {
equationExpression = value[0]
} else if (typeof text === 'string') {
equationExpression = text
}
break
}
case 'h':
if (typeof value === 'string') {
annotation.Color = value
@@ -429,6 +440,27 @@ function parseRichTexts(raw: any): RichText[] {
}
}
if (equationExpression) {
const richText: RichText = {
Equation: { Expression: equationExpression },
Annotation: { ...annotation },
PlainText: equationExpression,
}
if (href) {
richText.Href = href
}
if (mentionPageId) {
richText.Mention = {
Type: 'page',
Page: { Id: mentionPageId },
}
}
return richText
}
const richText = buildText(typeof text === 'string' ? text : '', href, {
Color: annotation.Color,
Bold: annotation.Bold,
@@ -747,6 +779,21 @@ function convertBlock(
},
}
}
case 'equation': {
const expression =
block.properties?.title?.[0]?.[0]?.toString() ||
block.properties?.equation?.[0]?.[0]?.toString() ||
''
if (!expression) return null
return {
Id: block.id,
Type: 'equation',
HasChildren: false,
Equation: { Expression: expression },
}
}
case 'tweet': {
const url = block.properties?.source?.[0]?.[0] || ''
if (!url) return null