Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export link regex for use in edit message #540

Merged
merged 7 commits into from
May 23, 2023
10 changes: 3 additions & 7 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Str from './str';
import {MARKDOWN_URL_REGEX, LOOSE_URL_REGEX, URL_REGEX} from './Url';
import {CONST} from './CONST';

const MARKDOWN_LINK_REGEX = `\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`;
const MARKDOWN_LINK_REGEX = new RegExp(`\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, 'gi');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Add a 'P' to the end of the name so we know it's not just a string MARKDOWN_LINK_REGEXP. Idk, maybe too subtle.


const SLACK_SPAN_NEW_LINE_TAG = '<span class="c-mrkdwn__br" data-stringify-type="paragraph-break" style="box-sizing: inherit; display: block; height: unset;"></span>';

Expand Down Expand Up @@ -74,10 +74,7 @@ export default class ExpensiMark {
*/
{
name: 'link',
process: (textToProcess, replacement) => {
const regex = new RegExp(MARKDOWN_LINK_REGEX, 'gi');
return this.modifyTextForUrlLinks(regex, textToProcess, replacement);
},
process: (textToProcess, replacement) => this.modifyTextForUrlLinks(MARKDOWN_LINK_REGEX, textToProcess, replacement),

replacement: (match, g1, g2) => {
if (g1.match(CONST.REG_EXP.EMOJIS) || !g1.trim()) {
Expand Down Expand Up @@ -727,9 +724,8 @@ export default class ExpensiMark {
* @returns {Array}
*/
extractLinksInMarkdownComment(comment) {
const regex = new RegExp(MARKDOWN_LINK_REGEX, 'gi');
const escapedComment = _.escape(comment);
const matches = [...escapedComment.matchAll(regex)];
const matches = [...escapedComment.matchAll(MARKDOWN_LINK_REGEX)];

// Element 1 from match is the regex group if it exists which contains the link URLs
const links = _.map(matches, match => Str.sanitizeURL(match[2]));
Expand Down