Skip to content

Commit

Permalink
Created and used constant to get the link in href inside anchor tag
Browse files Browse the repository at this point in the history
  • Loading branch information
samilabud committed May 20, 2024
1 parent 3857608 commit e4a4d6e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ const CONST = {

PULL_REQUEST_NUMBER,

// Regex to get link in href prop inside of <a/> component
REGEX_LINK_IN_ANCHOR: /<a\s+(?:[^>]*?\s+)?href="([^"]*)"/gi,

MERCHANT_NAME_MAX_LENGTH: 255,

REQUEST_PREVIEW: {
Expand Down
3 changes: 1 addition & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ function getMostRecentIOURequestActionID(reportActions: ReportAction[] | null):
function extractLinksFromMessageHtml(reportAction: OnyxEntry<ReportAction>): string[] {
const htmlContent = reportAction?.message?.[0]?.html;

// Regex to get link in href prop inside of <a/> component
const regex = /<a\s+(?:[^>]*?\s+)?href="([^"]*)"/gi;
const regex = CONST.REGEX_LINK_IN_ANCHOR;

if (!htmlContent) {
return [];
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ function setClipboardMessage(content: string) {
if (!Clipboard.canSetHtml()) {
Clipboard.setString(parser.htmlToMarkdown(content));
} else {
const anchorRegex = /<a\s+(?:[^>]*?\s+)?href="([^"]*)"/gi;
const anchorRegex = CONST.REGEX_LINK_IN_ANCHOR;
const isAnchorTag = anchorRegex.test(content);
console.log({isAnchorTag});
const plainText = isAnchorTag ? parser.htmlToMarkdown(content) : parser.htmlToText(content);
Clipboard.setHtml(content, plainText);
}
Expand Down

0 comments on commit e4a4d6e

Please sign in to comment.