-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathParser.ts
51 lines (43 loc) · 1.79 KB
/
Parser.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
// eslint-disable-next-line no-restricted-imports
import {ExpensiMark} from 'expensify-common';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import Log from './Log';
import * as ReportConnection from './ReportConnection';
const accountIDToNameMap: Record<string, string> = {};
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);
});
},
});
type Extras = {
reportIDToName?: Record<string, string>;
accountIDToName?: Record<string, string>;
cacheVideoAttributes?: (vidSource: string, attrs: string) => void;
videoAttributeCache?: Record<string, string>;
};
class ExpensiMarkWithContext extends ExpensiMark {
htmlToMarkdown(htmlString: string, extras?: Extras): string {
return super.htmlToMarkdown(htmlString, {
reportIDToName: extras?.reportIDToName ?? ReportConnection.getAllReportsNameMap(),
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap,
cacheVideoAttributes: extras?.cacheVideoAttributes,
});
}
htmlToText(htmlString: string, extras?: Extras): string {
return super.htmlToText(htmlString, {
reportIDToName: extras?.reportIDToName ?? ReportConnection.getAllReportsNameMap(),
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap,
cacheVideoAttributes: extras?.cacheVideoAttributes,
});
}
}
ExpensiMarkWithContext.setLogger(Log);
const Parser = new ExpensiMarkWithContext();
export default Parser;