expensify-common 2.0.4 → 2.0.6

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.
Files changed (2) hide show
  1. package/dist/ExpensiMark.js +34 -14
  2. package/package.json +1 -1
@@ -277,20 +277,20 @@ class ExpensiMark {
277
277
  return `<blockquote>${isStartingWithSpace ? ' ' : ''}${replacedText}</blockquote>`;
278
278
  },
279
279
  },
280
+ /**
281
+ * Use \b in this case because it will match on words, letters,
282
+ * and _: https://www.rexegg.com/regex-boundaries.html#wordboundary
283
+ * Use [\s\S]* instead of .* to match newline
284
+ */
280
285
  {
281
- /**
282
- * Use \b in this case because it will match on words, letters,
283
- * and _: https://www.rexegg.com/regex-boundaries.html#wordboundary
284
- * The !_blank is to prevent the `target="_blank">` section of the
285
- * link replacement from being captured Additionally, something like
286
- * `\b\_([^<>]*?)\_\b` doesn't work because it won't replace
287
- * `_https://www.test.com_`
288
- * Use [\s\S]* instead of .* to match newline
289
- */
290
286
  name: 'italic',
291
- regex: /(?<!<[^>]*)(\b_+|\b)(?!_blank")_((?![\s_])[\s\S]*?[^\s_](?<!\s))_(?![^\W_])(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>|<\/mention-user>|_blank))/g,
292
- // We want to add extraLeadingUnderscores back before the <em> tag unless textWithinUnderscores starts with valid email
293
- replacement: (match, extraLeadingUnderscores, textWithinUnderscores) => {
287
+ regex: /(<(pre|code|a|mention-user)[^>]*>(.*?)<\/\2>)|((\b_+|\b)_((?![\s_])[\s\S]*?[^\s_](?<!\s))_(?![^\W_])(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>|<\/mention-user>)))/g,
288
+ replacement: (match, html, tag, content, text, extraLeadingUnderscores, textWithinUnderscores) => {
289
+ // Skip any <pre>, <code>, <a>, <mention-user> tag contents
290
+ if (html) {
291
+ return html;
292
+ }
293
+ // If any tags are included inside underscores, ignore it. ie. _abc <pre>pre tag</pre> abc_
294
294
  if (textWithinUnderscores.includes('</pre>') || this.containsNonPairTag(textWithinUnderscores)) {
295
295
  return match;
296
296
  }
@@ -415,8 +415,28 @@ class ExpensiMark {
415
415
  .replace(/(<h1>|<\/h1>)+/g, '\n')
416
416
  .trim()
417
417
  .split('\n');
418
- const prependGreaterSign = (m) => `> ${m}`;
419
- resultString = _.map(resultString, prependGreaterSign).join('\n');
418
+ // Wrap each string in the array with <blockquote> and </blockquote>
419
+ // Define a named function to wrap each line with blockquote
420
+ function wrapWithBlockquote(line) {
421
+ return `<blockquote>${line}</blockquote>`;
422
+ }
423
+ // Use _.map with the named function
424
+ resultString = _.map(resultString, wrapWithBlockquote);
425
+ function processString(m) {
426
+ // Recursive function to replace nested <blockquote> with ">"
427
+ function replaceBlockquotes(text) {
428
+ let modifiedText = text;
429
+ let depth;
430
+ do {
431
+ depth = (modifiedText.match(/<blockquote>/gi) || []).length;
432
+ modifiedText = modifiedText.replace(/<blockquote>/gi, '');
433
+ modifiedText = modifiedText.replace(/<\/blockquote>/gi, '');
434
+ } while (/<blockquote>/i.test(modifiedText));
435
+ return `${'>'.repeat(depth)} ${modifiedText}`;
436
+ }
437
+ return replaceBlockquotes(m);
438
+ }
439
+ resultString = _.map(resultString, processString).join('\n');
420
440
  // We want to keep <blockquote> tag here and let method replaceBlockElementWithNewLine to handle the line break later
421
441
  return `<blockquote>${resultString}</blockquote>`;
422
442
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",