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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'underscore';
import Str from './str';
import {MARKDOWN_URL_REGEX, LOOSE_URL_REGEX, URL_REGEX} from './Url';
import {MARKDOWN_LINK_REGEX, MARKDOWN_URL_REGEX, LOOSE_URL_REGEX, URL_REGEX} from './Url';
import {CONST} from './CONST';

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 @@ -73,10 +73,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
2 changes: 2 additions & 0 deletions lib/Url.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const LOOSE_URL_REGEX = `((${LOOSE_URL_WEBSITE_REGEX})${URL_PATH_REGEX}(?:${URL_


const MARKDOWN_URL_REGEX = `(${LOOSE_URL_REGEX}|${URL_REGEX})`;
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.

This doesn't seem relevant here because it is about links, not just URLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to ExpensiMark.js


export {
URL_WEBSITE_REGEX,
Expand All @@ -28,4 +29,5 @@ export {
LOOSE_URL_REGEX,
LOOSE_URL_WEBSITE_REGEX,
MARKDOWN_URL_REGEX,
MARKDOWN_LINK_REGEX,
};