expensify-common 2.0.63 → 2.0.65

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 +31 -31
  2. package/package.json +2 -2
@@ -84,6 +84,29 @@ class ExpensiMark {
84
84
  return `<pre>${newLineCharacter}${group}</pre>`;
85
85
  },
86
86
  },
87
+ /**
88
+ * Converts markdown style video to video tags e.g. ![Expensify](https://www.expensify.com/attachment.mp4)
89
+ * We need to convert before image rules since they will not try to create a image tag from an existing video URL
90
+ * Extras arg could contain the attribute cache for the video tag which is cached during the html-to-markdown conversion
91
+ */
92
+ {
93
+ name: 'video',
94
+ regex: MARKDOWN_VIDEO_REGEX,
95
+ /**
96
+ * @param extras - The extras object
97
+ * @param videoName - The first capture group - video name
98
+ * @param videoSource - The second capture group - video URL
99
+ * @return Returns the HTML video tag
100
+ */
101
+ replacement: (extras, _match, videoName, videoSource) => {
102
+ const extraAttrs = extras && extras.videoAttributeCache && extras.videoAttributeCache[videoSource];
103
+ return `<video data-expensify-source="${str_1.default.sanitizeURL(videoSource)}" ${extraAttrs || ''}>${videoName ? `${videoName}` : ''}</video>`;
104
+ },
105
+ rawInputReplacement: (extras, _match, videoName, videoSource) => {
106
+ const extraAttrs = extras && extras.videoAttributeCache && extras.videoAttributeCache[videoSource];
107
+ 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>`;
108
+ },
109
+ },
87
110
  /**
88
111
  * Apply inline code-block to avoid applying any other formatting rules inside of it,
89
112
  * like we do for the multi-line code-blocks
@@ -93,7 +116,7 @@ class ExpensiMark {
93
116
  // Use the url escaped version of a backtick (`) symbol. Mobile platforms do not support lookbehinds,
94
117
  // so capture the first and third group and place them in the replacement.
95
118
  // but we should not replace backtick symbols if they include <pre> tags between them.
96
- regex: /(\B|_|)&#x60;(.*?(?![&#x60;])\S.*?)&#x60;(\B|_|)(?!&#x60;|[^<]*<\/pre>)/gm,
119
+ regex: /(\B|_|)&#x60;(.*?(?![&#x60;])\S.*?)&#x60;(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
97
120
  replacement: '$1<code>$2</code>$3',
98
121
  },
99
122
  /**
@@ -128,34 +151,11 @@ class ExpensiMark {
128
151
  {
129
152
  name: 'heading1',
130
153
  process: (textToProcess, replacement, shouldKeepRawInput = false) => {
131
- const regexp = shouldKeepRawInput ? /^# ( *(?! )(?:(?!<pre>|\n|\r\n).)+)/gm : /^# +(?! )((?:(?!<pre>|\n|\r\n).)+)/gm;
154
+ const regexp = shouldKeepRawInput ? /^# ( *(?! )(?:(?!<pre>|<video>|\n|\r\n).)+)/gm : /^# +(?! )((?:(?!<pre>|<video>|\n|\r\n).)+)/gm;
132
155
  return this.replaceTextWithExtras(textToProcess, regexp, EXTRAS_DEFAULT, replacement);
133
156
  },
134
157
  replacement: '<h1>$1</h1>',
135
158
  },
136
- /**
137
- * Converts markdown style video to video tags e.g. ![Expensify](https://www.expensify.com/attachment.mp4)
138
- * We need to convert before image rules since they will not try to create a image tag from an existing video URL
139
- * Extras arg could contain the attribute cache for the video tag which is cached during the html-to-markdown conversion
140
- */
141
- {
142
- name: 'video',
143
- regex: MARKDOWN_VIDEO_REGEX,
144
- /**
145
- * @param extras - The extras object
146
- * @param videoName - The first capture group - video name
147
- * @param videoSource - The second capture group - video URL
148
- * @return Returns the HTML video tag
149
- */
150
- replacement: (extras, _match, videoName, videoSource) => {
151
- const extraAttrs = extras && extras.videoAttributeCache && extras.videoAttributeCache[videoSource];
152
- return `<video data-expensify-source="${str_1.default.sanitizeURL(videoSource)}" ${extraAttrs || ''}>${videoName ? `${videoName}` : ''}</video>`;
153
- },
154
- rawInputReplacement: (extras, _match, videoName, videoSource) => {
155
- const extraAttrs = extras && extras.videoAttributeCache && extras.videoAttributeCache[videoSource];
156
- 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>`;
157
- },
158
- },
159
159
  /**
160
160
  * Converts markdown style images to image tags e.g. ![Expensify](https://www.expensify.com/attachment.png)
161
161
  * We need to convert before linking rules since they will not try to create a link from an existing img
@@ -280,9 +280,9 @@ class ExpensiMark {
280
280
  // block quotes naturally appear on their own line. Blockquotes should not appear in code fences or
281
281
  // inline code blocks. A single prepending space should be stripped if it exists
282
282
  process: (textToProcess, replacement, shouldKeepRawInput = false) => {
283
- const regex = /^(?:&gt;)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]+)/gm;
283
+ const regex = /^(?:&gt;)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>|<\/video>))([^\v\n\r]+)/gm;
284
284
  if (shouldKeepRawInput) {
285
- const rawInputRegex = /^(?:&gt;)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>))([^\v\n\r]*)/gm;
285
+ const rawInputRegex = /^(?:&gt;)+ +(?! )(?![^<]*(?:<\/pre>|<\/code>|<\/video>))([^\v\n\r]*)/gm;
286
286
  return this.replaceTextWithExtras(textToProcess, rawInputRegex, EXTRAS_DEFAULT, replacement);
287
287
  }
288
288
  return this.modifyTextForQuote(regex, textToProcess, replacement);
@@ -337,9 +337,9 @@ class ExpensiMark {
337
337
  */
338
338
  {
339
339
  name: 'italic',
340
- regex: /(<(pre|code|a|mention-user)[^>]*>(.*?)<\/\2>)|((\b_+|\b)_((?![\s_])[\s\S]*?[^\s_](?<!\s))_(?![^\W_])(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>|<\/mention-user>)))/g,
340
+ regex: /(<(pre|code|a|mention-user|video)[^>]*>(.*?)<\/\2>)|((\b_+|\b)_((?![\s_])[\s\S]*?[^\s_](?<!\s))_(?![^\W_])(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>|<\/mention-user>|<\/video>)))/g,
341
341
  replacement: (_extras, match, html, tag, content, text, extraLeadingUnderscores, textWithinUnderscores) => {
342
- // Skip any <pre>, <code>, <a>, <mention-user> tag contents
342
+ // Skip any <pre>, <code>, <a>, <mention-user>, <video> tag contents
343
343
  if (html) {
344
344
  return html;
345
345
  }
@@ -369,7 +369,7 @@ class ExpensiMark {
369
369
  // \B will match everything that \b doesn't, so it works
370
370
  // for * and ~: https://www.rexegg.com/regex-boundaries.html#notb
371
371
  name: 'bold',
372
- regex: /(?<!<[^>]*)(\b_|\B)\*(?![^<]*(?:<\/pre>|<\/code>|<\/a>))((?![\s*])[\s\S]*?[^\s*](?<!\s))\*\B(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,
372
+ regex: /(?<!<[^>]*)(\b_|\B)\*(?![^<]*(?:<\/pre>|<\/code>|<\/a>|<\/video>))((?![\s*])[\s\S]*?[^\s*](?<!\s))\*\B(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>|<\/video>))/g,
373
373
  replacement: (_extras, match, g1, g2) => {
374
374
  if (g1.includes('_')) {
375
375
  return `${g1}<strong>${g2}</strong>`;
@@ -379,7 +379,7 @@ class ExpensiMark {
379
379
  },
380
380
  {
381
381
  name: 'strikethrough',
382
- regex: /(?<!<[^>]*)\B~((?![\s~])[\s\S]*?[^\s~](?<!\s))~\B(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>))/g,
382
+ regex: /(?<!<[^>]*)\B~((?![\s~])[\s\S]*?[^\s~](?<!\s))~\B(?![^<]*>)(?![^<]*(<\/pre>|<\/code>|<\/a>|<\/video>))/g,
383
383
  replacement: (_extras, match, g1) => (g1.includes('</pre>') || this.containsNonPairTag(g1) ? match : `<del>${g1}</del>`),
384
384
  },
385
385
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.63",
3
+ "version": "2.0.65",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",
@@ -43,7 +43,7 @@
43
43
  "ua-parser-js": "^1.0.38"
44
44
  },
45
45
  "devDependencies": {
46
- "@babel/preset-env": "^7.24.5",
46
+ "@babel/preset-env": "^7.24.8",
47
47
  "@lwc/eslint-plugin-lwc": "^1.8.2",
48
48
  "@babel/preset-typescript": "^7.24.7",
49
49
  "@types/jest": "^29.5.12",