fix: enhance ExportService to support nested bold and italic formatting (#6420)

* fix: enhance ExportService to support nested bold and italic formatting

- Added tracking for nested bold and italic tags in the ExportService.
- Updated text rendering logic to apply bold and italic styles based on the nesting level of the tags.

* fix: remove unused citation variable in messageToMarkdown function
This commit is contained in:
SuYao 2025-05-25 21:08:47 +08:00 committed by GitHub
parent 94792c9bb1
commit f462b7f94e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -47,6 +47,8 @@ export class ExportService {
let linkText = '' let linkText = ''
let linkUrl = '' let linkUrl = ''
let insideLink = false let insideLink = false
let boldStack = 0 // 跟踪嵌套的粗体标记
let italicStack = 0 // 跟踪嵌套的斜体标记
for (let i = 0; i < tokens.length; i++) { for (let i = 0; i < tokens.length; i++) {
const token = tokens[i] const token = tokens[i]
@ -82,17 +84,37 @@ export class ExportService {
insideLink = false insideLink = false
} }
break break
case 'strong_open':
boldStack++
break
case 'strong_close':
boldStack--
break
case 'em_open':
italicStack++
break
case 'em_close':
italicStack--
break
case 'text': case 'text':
runs.push(new TextRun({ text: token.content, bold: isHeaderRow })) runs.push(
break new TextRun({
case 'strong': text: token.content,
runs.push(new TextRun({ text: token.content, bold: true })) bold: isHeaderRow || boldStack > 0,
break italics: italicStack > 0
case 'em': })
runs.push(new TextRun({ text: token.content, italics: true })) )
break break
case 'code_inline': case 'code_inline':
runs.push(new TextRun({ text: token.content, font: 'Consolas', size: 20 })) runs.push(
new TextRun({
text: token.content,
font: 'Consolas',
size: 20,
bold: isHeaderRow || boldStack > 0,
italics: italicStack > 0
})
)
break break
} }
} }