Skip to content

Commit

Permalink
fix: remove duplicated code related to MARKDOWN_LINK_REGEX
Browse files Browse the repository at this point in the history
  • Loading branch information
sangar-1028 committed May 23, 2023
1 parent b8c6e59 commit 7312a08
Showing 1 changed file with 3 additions and 7 deletions.
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');

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

0 comments on commit 7312a08

Please sign in to comment.