diff --git a/lib/ExpensiMark.d.ts b/lib/ExpensiMark.d.ts index 529e7b52..4a795072 100644 --- a/lib/ExpensiMark.d.ts +++ b/lib/ExpensiMark.d.ts @@ -8,6 +8,19 @@ declare type Rule = { pre?: (input: string) => string; post?: (input: string) => string; }; + +declare type PersonalDetail = { + accountID: string; + login?: string; + displayName?: string +} + +declare type PersonalDetails = Record | {} + +declare type Metadata = { + personalDetails?: PersonalDetails +} + export default class ExpensiMark { rules: Rule[]; htmlToMarkdownRules: Rule[]; @@ -56,14 +69,16 @@ export default class ExpensiMark { * Replaces HTML with markdown * * @param htmlString + * @param metadata */ - htmlToMarkdown(htmlString: string): string; + htmlToMarkdown(htmlString: string, metadata?: Metadata): string; /** * Convert HTML to text * * @param htmlString + * @param metadata */ - htmlToText(htmlString: string): string; + htmlToText(htmlString: string, metadata?: Metadata): string; /** * Modify text for Quotes replacing chevrons with html elements * diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index a1b01095..d50d9e8a 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -7,6 +7,12 @@ const MARKDOWN_LINK_REGEX = new RegExp(`\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\ const SLACK_SPAN_NEW_LINE_TAG = ''; +const userMentionReplacement = (openTag, accountID, closeTag, personalDetails = {}) => { + const user = _.get(personalDetails, accountID); + const displayNameOrLogin = _.get(user, 'login', '') || _.get(user, 'displayName', ''); + return `${openTag}@${displayNameOrLogin}${closeTag}`; +}; + export default class ExpensiMark { constructor() { /** @@ -350,6 +356,16 @@ export default class ExpensiMark { return `[${g4}](${email || g3})`; }, }, + { + name: 'mentionUser', + regex: /()(<\/mention-user>)/gi, + replacement: userMentionReplacement, + }, + { + name: 'mentionUser', + regex: /()(<\/mention-user>)/gi, + replacement: userMentionReplacement, + }, ]; /** @@ -388,6 +404,11 @@ export default class ExpensiMark { regex: /