mirror of
https://github.com/lbr77/blog-astro.git
synced 2026-04-09 00:19:12 +00:00
katex parse
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user