mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 10:00:08 +08:00
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:
parent
94792c9bb1
commit
f462b7f94e
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user