expensify-common 2.0.38 → 2.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -449,7 +449,29 @@ class ExpensiMark {
449
449
  {
450
450
  name: 'bold',
451
451
  regex: /<(b|strong)(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/\1>(?![^<]*(<\/pre>|<\/code>))/gi,
452
- replacement: '*$2*',
452
+ replacement: (extras, match, tagName, innerContent) => {
453
+ // To check if style attribute contains bold font-weight
454
+ const isBoldFromStyle = (style) => {
455
+ return style ? style.replace(/\s/g, '').includes('font-weight:bold;') || style.replace(/\s/g, '').includes('font-weight:700;') : false;
456
+ };
457
+ const updateSpacesAndWrapWithAsterisksIfBold = (content, isBold) => {
458
+ const trimmedContent = content.trim();
459
+ const leadingSpace = content.startsWith(' ') ? ' ' : '';
460
+ const trailingSpace = content.endsWith(' ') ? ' ' : '';
461
+ return isBold ? `${leadingSpace}*${trimmedContent}*${trailingSpace}` : content;
462
+ };
463
+ // Determine if the outer tag is bold
464
+ const styleAttributeMatch = match.match(/style="(.*?)"/);
465
+ const isFontWeightBold = isBoldFromStyle(styleAttributeMatch ? styleAttributeMatch[1] : null);
466
+ const isBold = styleAttributeMatch ? isFontWeightBold : tagName === 'b' || tagName === 'strong';
467
+ // Process nested spans with potential bold style
468
+ const processedInnerContent = innerContent.replace(/<span(?:"[^"]*"|'[^']*'|[^'">])*>([\s\S]*?)<\/span>/gi, (nestedMatch, nestedContent) => {
469
+ const nestedStyleMatch = nestedMatch.match(/style="(.*?)"/);
470
+ const isNestedBold = isBoldFromStyle(nestedStyleMatch ? nestedStyleMatch[1] : null);
471
+ return updateSpacesAndWrapWithAsterisksIfBold(nestedContent, isNestedBold);
472
+ });
473
+ return updateSpacesAndWrapWithAsterisksIfBold(processedInnerContent, isBold);
474
+ },
453
475
  },
454
476
  {
455
477
  name: 'strikethrough',
@@ -541,7 +563,7 @@ class ExpensiMark {
541
563
  },
542
564
  {
543
565
  name: 'reportMentions',
544
- regex: /<mention-report reportID="(\d+)" *\/>/gi,
566
+ regex: /<mention-report reportID="(\d+)"(?: *\/>|><\/mention-report>)/gi,
545
567
  replacement: (extras, _match, g1, _offset, _string) => {
546
568
  const reportToNameMap = extras.reportIDToName;
547
569
  if (!reportToNameMap || !reportToNameMap[g1]) {
@@ -553,7 +575,7 @@ class ExpensiMark {
553
575
  },
554
576
  {
555
577
  name: 'userMention',
556
- regex: /(?:<mention-user accountID="(\d+)" *\/>)|(?:<mention-user>(.*?)<\/mention-user>)/gi,
578
+ regex: /(?:<mention-user accountID="(\d+)"(?: *\/>|><\/mention-user>))|(?:<mention-user>(.*?)<\/mention-user>)/gi,
557
579
  replacement: (extras, _match, g1, g2, _offset, _string) => {
558
580
  var _a, _b;
559
581
  if (g1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.38",
3
+ "version": "2.0.40",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",