From f462b7f94e64f88dc3aa9db5aff18a56a8ce562c Mon Sep 17 00:00:00 2001 From: SuYao Date: Sun, 25 May 2025 21:08:47 +0800 Subject: [PATCH] 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 --- src/main/services/ExportService.ts | 38 +++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/services/ExportService.ts b/src/main/services/ExportService.ts index 7f58ccafa1..b17acc9bde 100644 --- a/src/main/services/ExportService.ts +++ b/src/main/services/ExportService.ts @@ -47,6 +47,8 @@ export class ExportService { let linkText = '' let linkUrl = '' let insideLink = false + let boldStack = 0 // 跟踪嵌套的粗体标记 + let italicStack = 0 // 跟踪嵌套的斜体标记 for (let i = 0; i < tokens.length; i++) { const token = tokens[i] @@ -82,17 +84,37 @@ export class ExportService { insideLink = false } break + case 'strong_open': + boldStack++ + break + case 'strong_close': + boldStack-- + break + case 'em_open': + italicStack++ + break + case 'em_close': + italicStack-- + break case 'text': - runs.push(new TextRun({ text: token.content, bold: isHeaderRow })) - break - case 'strong': - runs.push(new TextRun({ text: token.content, bold: true })) - break - case 'em': - runs.push(new TextRun({ text: token.content, italics: true })) + runs.push( + new TextRun({ + text: token.content, + bold: isHeaderRow || boldStack > 0, + italics: italicStack > 0 + }) + ) break 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 } }