From 55dea44c7bbc3c2bb53c71fefd8caa84b86379fb Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 10 Nov 2023 11:50:46 +0700 Subject: [PATCH 1/3] add mention user rule --- lib/ExpensiMark.d.ts | 14 ++++++++++++-- lib/ExpensiMark.js | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/ExpensiMark.d.ts b/lib/ExpensiMark.d.ts index 529e7b52..687d0f23 100644 --- a/lib/ExpensiMark.d.ts +++ b/lib/ExpensiMark.d.ts @@ -8,6 +8,15 @@ declare type Rule = { pre?: (input: string) => string; post?: (input: string) => string; }; + +declare type PersonalDetail = { + accountID: string; + login?: string; + displayName?: string +} + +declare type PersonalDetails = Record | {} + export default class ExpensiMark { rules: Rule[]; htmlToMarkdownRules: Rule[]; @@ -57,13 +66,14 @@ export default class ExpensiMark { * * @param htmlString */ - htmlToMarkdown(htmlString: string): string; + htmlToMarkdown(htmlString: string, personalDetails: PersonalDetails): string; /** * Convert HTML to text * * @param htmlString + * @param personalDetails */ - htmlToText(htmlString: string): string; + htmlToText(htmlString: string, personalDetails: PersonalDetails): string; /** * Modify text for Quotes replacing chevrons with html elements * diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index a1b01095..6c15e06f 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -350,6 +350,15 @@ export default class ExpensiMark { return `[${g4}](${email || g3})`; }, }, + { + name: 'mentionUser', + regex: /()(<\/mention-user>)/gi, + replacement: (openTag, accountID, closeTag, personalDetails) => { + const user = _.get(personalDetails, accountID); + const displayNameOrLogin = _.get(user, 'login', '') || _.get(user, 'displayName', ''); + return `${openTag}@${displayNameOrLogin}${closeTag}`; + } + }, ]; /** @@ -388,6 +397,15 @@ export default class ExpensiMark { regex: /