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
11 changes: 7 additions & 4 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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>))`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this to Url.js

Copy link
Contributor Author

@s-alves10 s-alves10 May 22, 2023

Choose a reason for hiding this comment

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

@aimane-chnaif
I intentionally placed this constant in ExpensiMark.js. This is not the URL regex, is the regex for parsing markdown URL.
Should I still move this regex to Url.js?

Copy link
Contributor

Choose a reason for hiding this comment

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

Still I suggest Url.js.
There's no non-default exported const or function defined in ExpensiMark.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved

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>';

export default class ExpensiMark {
Expand Down Expand Up @@ -106,10 +108,7 @@ export default class ExpensiMark {
{
name: 'link',
process: (textToProcess, replacement) => {
const regex = new RegExp(
`\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\\(${MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`,
'gi',
);
const regex = new RegExp(MARKDOWN_LINK_REGEX, 'gi');
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's we're building a regex with the 'gi' flags, but in App we're using the 'gm' flags. That's an example of an inconsistency with this approach.

Copy link
Contributor Author

@s-alves10 s-alves10 May 22, 2023

Choose a reason for hiding this comment

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

@neil-marcellini
I think gi flag is intentional not to parse multiline link. In App, we'll be using gi flags as well.
Actually, ExpensiMark uses this flag for both link and autolink at the moment.

return this.modifyTextForUrlLinks(regex, textToProcess, replacement);
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
},

Expand Down Expand Up @@ -721,3 +720,7 @@ export default class ExpensiMark {
return tagStack.length !== 0;
}
}

export {
MARKDOWN_LINK_REGEX
};