From 694b521b2ea3cff71d14003abdd80027918663cc Mon Sep 17 00:00:00 2001 From: sub-hub Date: Tue, 7 May 2024 11:09:48 +0900 Subject: [PATCH] Fix: handling strong, em in getNodetextToSentence --- src/ts/util.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ts/util.ts b/src/ts/util.ts index ca3dd7f0..3f470a7a 100644 --- a/src/ts/util.ts +++ b/src/ts/util.ts @@ -554,9 +554,25 @@ export function getNodetextToSentence(node: Node): string { } else if (child.nodeType === Node.ELEMENT_NODE) { if (child.nodeName === 'BR') { result += '\n'; - } else if (child.nodeName === 'DEL') { + continue; + } + + // If a child has a style it's not for a markdown formatting + const childStyle = (child as HTMLElement)?.style; + if (childStyle?.cssText!== '') { + result += getNodetextToSentence(child); + continue; + } + + // convert HTML elements to markdown format + if (child.nodeName === 'DEL') { result += '~' + getNodetextToSentence(child) + '~'; - } else { + } else if (child.nodeName === 'STRONG' || child.nodeName === 'B') { + result += '**' + getNodetextToSentence(child) + '**'; + } else if (child.nodeName === 'EM' || child.nodeName === 'I') { + result += '*' + getNodetextToSentence(child) + '*'; + } + else { result += getNodetextToSentence(child); } }