Skip to content

Commit

Permalink
Merge pull request #783 from bernhardoj/fix/copy-bold-text-from-other…
Browse files Browse the repository at this point in the history
…-app-doesnt-render-as-bold

Fix bold tag isn't rendered as markdown when it has a style
  • Loading branch information
aldo-expensify authored Aug 20, 2024
2 parents e14dff6 + a3f68f5 commit a30864e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ test('Test bold HTML replacement', () => {
const boldTestStartString = 'This is a <strong>sentence,</strong> and it has some <strong>punctuation, words, and spaces</strong>. '
+ '<strong>test</strong> * testing* test*test*test. * testing * *testing * '
+ 'This is a <b>sentence,</b> and it has some <b>punctuation, words, and spaces</b>. '
+ 'This is a <b style="font-size: 20px;">bold sentence with style</b> '
+ '<b>test</b> * 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);
Expand Down
5 changes: 3 additions & 2 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<span(?:"[^"]*"|'[^']*'|[^'">])*>([\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);
});
Expand Down

0 comments on commit a30864e

Please sign in to comment.