diff --git a/__tests__/ExpensiMark-Markdown-test.js b/__tests__/ExpensiMark-Markdown-test.js index 297c8971..1ebfd21a 100644 --- a/__tests__/ExpensiMark-Markdown-test.js +++ b/__tests__/ExpensiMark-Markdown-test.js @@ -7,10 +7,12 @@ test('Test bold HTML replacement', () => { const boldTestStartString = 'This is a sentence, and it has some punctuation, words, and spaces. ' + 'test * testing* test*test*test. * testing * *testing * ' + 'This is a sentence, and it has some punctuation, words, and spaces. ' + + 'This is a bold sentence with style ' + 'test * testing* test*test*test. * testing * *testing *'; const boldTestReplacedString = 'This is a *sentence,* and it has some *punctuation, words, and spaces*. ' + '*test* * testing* test*test*test. * testing * *testing * ' + 'This is a *sentence,* and it has some *punctuation, words, and spaces*. ' + + 'This is a *bold sentence with style* ' + '*test* * testing* test*test*test. * testing * *testing *'; expect(parser.htmlToMarkdown(boldTestStartString)).toBe(boldTestReplacedString); diff --git a/lib/ExpensiMark.ts b/lib/ExpensiMark.ts index 8b97487c..7820b8f8 100644 --- a/lib/ExpensiMark.ts +++ b/lib/ExpensiMark.ts @@ -576,13 +576,14 @@ export default class ExpensiMark { }; // Determine if the outer tag is bold - const styleAttributeMatch = match.match(/style="(.*?)"/); + const fontWeightRegex = /style="([^"]*?\bfont-weight:\s*(\d+|bold|normal)[^"]*?)"/; + const styleAttributeMatch = match.match(fontWeightRegex); const isFontWeightBold = isBoldFromStyle(styleAttributeMatch ? styleAttributeMatch[1] : null); const isBold = styleAttributeMatch ? isFontWeightBold : tagName === 'b' || tagName === 'strong'; // Process nested spans with potential bold style const processedInnerContent = innerContent.replace(/])*>([\s\S]*?)<\/span>/gi, (nestedMatch, nestedContent) => { - const nestedStyleMatch = nestedMatch.match(/style="(.*?)"/); + const nestedStyleMatch = nestedMatch.match(fontWeightRegex); const isNestedBold = isBoldFromStyle(nestedStyleMatch ? nestedStyleMatch[1] : null); return updateSpacesAndWrapWithAsterisksIfBold(nestedContent, isNestedBold); });