-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathutils.ts
More file actions
29 lines (26 loc) · 909 Bytes
/
utils.ts
File metadata and controls
29 lines (26 loc) · 909 Bytes
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
import { PluggableList, Pluggable } from 'unified';
import { rehype } from 'rehype';
export const processHtml = (html: string, plugins: PluggableList = [] as Pluggable[]) => {
return rehype()
.data('settings', { fragment: true })
.use([...plugins])
.processSync(`${html}`)
.toString();
};
export function htmlEncode(sHtml: string) {
return sHtml
.replace(/```(tsx?|jsx?|html|xml)(.*)\s+([\s\S]*?)(\s.+)?```/g, (str: string) => {
return str.replace(
/[<&"]/g,
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' }) as Record<string, string>)[c],
);
})
.replace(
/[<&"]/g,
(c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' }) as Record<string, string>)[c],
);
}
export function stopPropagation(e: React.KeyboardEvent<HTMLTextAreaElement>) {
e.stopPropagation();
e.preventDefault();
}