-
Notifications
You must be signed in to change notification settings - Fork 135
/
ExpensiMark.d.ts
142 lines (141 loc) · 4.44 KB
/
ExpensiMark.d.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
declare type Replacement = (...args: string[], extras?: ExtrasObject) => string;
declare type Name =
| 'codeFence'
| 'inlineCodeBlock'
| 'email'
| 'link'
| 'hereMentions'
| 'userMentions'
| 'reportMentions'
| 'autoEmail'
| 'autolink'
| 'quote'
| 'italic'
| 'bold'
| 'strikethrough'
| 'heading1'
| 'newline'
| 'replacepre'
| 'listItem'
| 'exclude'
| 'anchor'
| 'breakline'
| 'blockquoteWrapHeadingOpen'
| 'blockquoteWrapHeadingClose'
| 'blockElementOpen'
| 'blockElementClose'
| 'stripTag';
declare type Rule = {
name: Name;
process?: (textToProcess: string, replacement: Replacement) => string;
regex?: RegExp;
replacement: Replacement | string;
pre?: (input: string) => string;
post?: (input: string) => string;
};
declare type ExtrasObject = {
reportIdToName?: Record<string, string>;
accountIDToName?: Record<string, string>;
};
export default class ExpensiMark {
rules: Rule[];
htmlToMarkdownRules: Rule[];
htmlToTextRules: Rule[];
constructor();
/**
* Replaces markdown with html elements
*
* @param text - Text to parse as markdown
* @param options - Options to customize the markdown parser
* @param options.filterRules=[] - An array of name of rules as defined in this class.
* If not provided, all available rules will be applied. If provided, only the rules in the array will be applied.
* @param options.disabledRules=[] - An array of name of rules as defined in this class.
* If not provided, all available rules will be applied. If provided, the rules in the array will be skipped.
* @param options.shouldEscapeText=true - Whether or not the text should be escaped
* @param options.shouldKeepRawInput=false - Whether or not the raw input should be kept and returned
*/
replace(
text: string,
{
filterRules,
shouldEscapeText,
shouldKeepRawInput,
}?: {
filterRules?: Name[];
disabledRules?: Name[];
shouldEscapeText?: boolean;
shouldKeepRawInput?: boolean;
},
): string;
/**
* Checks matched URLs for validity and replace valid links with html elements
*
* @param regex
* @param textToCheck
* @param replacement
*/
modifyTextForUrlLinks(regex: RegExp, textToCheck: string, replacement: Replacement): string;
/**
* Checks matched Emails for validity and replace valid links with html elements
*
* @param regex
* @param textToCheck
* @param replacement
*/
modifyTextForEmailLinks(regex: RegExp, textToCheck: string, replacement: Replacement): string;
/**
* replace block element with '\n' if :
* 1. We have text within the element.
* 2. The text does not end with a new line.
* 3. The text does not have quote mark '>' .
* 4. It's not the last element in the string.
*
* @param htmlString
*/
replaceBlockElementWithNewLine(htmlString: string): string;
/**
* Replaces HTML with markdown
*
* @param htmlString
* @param extras
*/
htmlToMarkdown(htmlString: string, extras?: ExtrasObject): string;
/**
* Convert HTML to text
*
* @param htmlString
* @param extras
*/
htmlToText(htmlString: string, extras?: ExtrasObject): string;
/**
* Modify text for Quotes replacing chevrons with html elements
*
* @param regex
* @param textToCheck
* @param replacement
*/
modifyTextForQuote(regex: RegExp, textToCheck: string, replacement: Replacement): string;
/**
* Format the content of blockquote if the text matches the regex or else just return the original text
*
* @param regex
* @param textToCheck
* @param replacement
*/
formatTextForQuote(regex: RegExp, textToCheck: string, replacement: Replacement): string;
/**
* Check if the input text includes only the open or the close tag of an element.
*
* @param textToCheck - Text to check
*/
containsNonPairTag(textToCheck: string): boolean;
extractLinksInMarkdownComment(comment: string): string[] | undefined;
/**
* Compares two markdown comments and returns a list of the links removed in a new comment.
*
* @param oldComment
* @param newComment
*/
getRemovedMarkdownLinks(oldComment: string, newComment: string): string[];
}
export {};