expensify-common 2.0.171 → 2.0.174

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.includes(`.${extension}`));
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',
@@ -807,6 +821,9 @@ class ExpensiMark {
807
821
  * If not provided, all available rules will be applied. If provided, the rules in the array will be skipped.
808
822
  */
809
823
  replace(text, { filterRules = [], shouldEscapeText = true, shouldKeepRawInput = false, disabledRules = [], extras = EXTRAS_DEFAULT } = {}) {
824
+ if (!text) {
825
+ return '';
826
+ }
810
827
  // This ensures that any html the user puts into the comment field shows as raw html
811
828
  let replacedText = shouldEscapeText ? Utils.escapeText(text) : text;
812
829
  const rules = this.getHtmlRuleset(filterRules, disabledRules, shouldKeepRawInput);
@@ -815,6 +832,9 @@ class ExpensiMark {
815
832
  if (rule.pre) {
816
833
  replacedText = rule.pre(replacedText);
817
834
  }
835
+ if (rule.shouldSkipProcessing && rule.shouldSkipProcessing(replacedText)) {
836
+ return;
837
+ }
818
838
  const replacement = shouldKeepRawInput && rule.rawInputReplacement ? rule.rawInputReplacement : rule.replacement;
819
839
  if ('process' in rule) {
820
840
  replacedText = rule.process(replacedText, replacement, shouldKeepRawInput);
@@ -1056,6 +1076,9 @@ class ExpensiMark {
1056
1076
  * Replaces HTML with markdown
1057
1077
  */
1058
1078
  htmlToMarkdown(htmlString, extras = EXTRAS_DEFAULT) {
1079
+ if (!htmlString) {
1080
+ return '';
1081
+ }
1059
1082
  let generatedMarkdown = htmlString;
1060
1083
  const body = /<(body)(?:"[^"]*"|'[^']*'|[^'"><])*>(?:\n|\r\n)?([\s\S]*?)(?:\n|\r\n)?<\/\1>(?![^<]*(<\/pre>|<\/code>))/im;
1061
1084
  const parseBodyTag = generatedMarkdown.match(body);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.171",
3
+ "version": "2.0.174",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",