-
Notifications
You must be signed in to change notification settings - Fork 3k
/
OnyxAwareParser.ts
52 lines (43 loc) · 1.72 KB
/
OnyxAwareParser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {ExpensiMark} from 'expensify-common';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
const parser = new ExpensiMark();
const reportIDToNameMap: Record<string, string> = {};
const accountIDToNameMap: Record<string, string> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
callback: (report) => {
if (!report) {
return;
}
reportIDToNameMap[report.reportID] = report.reportName ?? report.displayName ?? report.reportID;
},
});
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (personalDetailsList) => {
Object.values(personalDetailsList ?? {}).forEach((personalDetails) => {
if (!personalDetails) {
return;
}
accountIDToNameMap[personalDetails.accountID] = personalDetails.login ?? String(personalDetails.accountID);
});
},
});
function parseHtmlToMarkdown(
html: string,
reportIDToName?: Record<string, string>,
accountIDToName?: Record<string, string>,
cacheVideoAttributes?: (videoSource: string, videoAttrs: string) => void,
): string {
return parser.htmlToMarkdown(html, {reportIDToName: reportIDToName ?? reportIDToNameMap, accountIDToName: accountIDToName ?? accountIDToNameMap, cacheVideoAttributes});
}
function parseHtmlToText(
html: string,
reportIDToName?: Record<string, string>,
accountIDToName?: Record<string, string>,
cacheVideoAttributes?: (videoSource: string, videoAttrs: string) => void,
): string {
return parser.htmlToText(html, {reportIDToName: reportIDToName ?? reportIDToNameMap, accountIDToName: accountIDToName ?? accountIDToNameMap, cacheVideoAttributes});
}
export {parseHtmlToMarkdown, parseHtmlToText};