expensify-common 2.0.173 → 2.0.175

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.
@@ -31,6 +31,7 @@ type CommonRule = {
31
31
  rawInputReplacement?: Replacement;
32
32
  pre?: (input: string) => string;
33
33
  post?: (input: string) => string;
34
+ shouldSkipProcessing?: (textToCheck: string) => boolean;
34
35
  };
35
36
  type RuleWithRegex = CommonRule & {
36
37
  regex: RegExp;
@@ -128,6 +128,11 @@ class ExpensiMark {
128
128
  const extraAttrs = attrCache && attrCache[videoSource];
129
129
  return `<video data-expensify-source="${str_1.default.sanitizeURL(videoSource)}" data-raw-href="${videoSource}" data-link-variant="${typeof videoName === 'string' ? 'labeled' : 'auto'}" ${extraAttrs || ''}>${videoName ? `${videoName}` : ''}</video>`;
130
130
  },
131
+ shouldSkipProcessing: (textToCheck) => {
132
+ const missingSpecialCharacters = !textToCheck.includes('!') || !textToCheck.includes('(') || !textToCheck.includes(')');
133
+ const missingVideoExtension = !Constants.CONST.VIDEO_EXTENSIONS.some((extension) => textToCheck.toLowerCase().includes(`.${extension.toLowerCase()}`));
134
+ return missingSpecialCharacters || missingVideoExtension;
135
+ },
131
136
  },
132
137
  /**
133
138
  * Apply inline code-block to avoid applying any other formatting rules inside of it,
@@ -208,6 +213,9 @@ class ExpensiMark {
208
213
  const extraAttrs = attrCache && attrCache[imgSource];
209
214
  return `<img src="${str_1.default.sanitizeURL(imgSource)}"${imgAlt ? ` alt="${this.escapeAttributeContent(imgAlt)}"` : ''} data-raw-href="${imgSource}" data-link-variant="${typeof imgAlt === 'string' ? 'labeled' : 'auto'}" ${extraAttrs || ''}/>`;
210
215
  },
216
+ shouldSkipProcessing: (textToCheck) => {
217
+ return !textToCheck.includes('!') || !textToCheck.includes('(') || !textToCheck.includes(')');
218
+ },
211
219
  },
212
220
  /**
213
221
  * Converts markdown style links to anchor tags e.g. [Expensify](https://www.expensify.com)
@@ -229,6 +237,9 @@ class ExpensiMark {
229
237
  }
230
238
  return `<a href="${str_1.default.sanitizeURL(g2)}" data-raw-href="${g2}" data-link-variant="labeled" target="_blank" rel="noreferrer noopener">${g1}</a>`;
231
239
  },
240
+ shouldSkipProcessing: (textToCheck) => {
241
+ return !textToCheck.includes('.');
242
+ },
232
243
  },
233
244
  /**
234
245
  * Apply the hereMention first because the string @here is still a valid mention for the userMention regex.
@@ -313,6 +324,9 @@ class ExpensiMark {
313
324
  const href = str_1.default.sanitizeURL(g2);
314
325
  return `${g1}<a href="${href}" data-raw-href="${g2}" data-link-variant="auto" target="_blank" rel="noreferrer noopener">${g2}</a>${g1}`;
315
326
  },
327
+ shouldSkipProcessing: (textToCheck) => {
328
+ return !textToCheck.includes('.');
329
+ },
316
330
  },
317
331
  {
318
332
  name: 'quote',
@@ -818,6 +832,9 @@ class ExpensiMark {
818
832
  if (rule.pre) {
819
833
  replacedText = rule.pre(replacedText);
820
834
  }
835
+ if (rule.shouldSkipProcessing && rule.shouldSkipProcessing(replacedText)) {
836
+ return;
837
+ }
821
838
  const replacement = shouldKeepRawInput && rule.rawInputReplacement ? rule.rawInputReplacement : rule.replacement;
822
839
  if ('process' in rule) {
823
840
  replacedText = rule.process(replacedText, replacement, shouldKeepRawInput);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.173",
3
+ "version": "2.0.175",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",