|
@@ -2,18 +2,17 @@ import { TextBlot } from 'parchment';
|
|
|
|
|
|
class Text extends TextBlot {}
|
|
|
|
|
|
+// https://lodash.com/docs#escape
|
|
|
+const entityMap: Record<string, string> = {
|
|
|
+ '&': '&',
|
|
|
+ '<': '<',
|
|
|
+ '>': '>',
|
|
|
+ '"': '"',
|
|
|
+ "'": ''',
|
|
|
+};
|
|
|
+
|
|
|
function escapeText(text: string) {
|
|
|
- return text.replace(/[&<>"']/g, (s) => {
|
|
|
- // https://lodash.com/docs#escape
|
|
|
- const entityMap: Record<string, string> = {
|
|
|
- '&': '&',
|
|
|
- '<': '<',
|
|
|
- '>': '>',
|
|
|
- '"': '"',
|
|
|
- "'": ''',
|
|
|
- };
|
|
|
- return entityMap[s];
|
|
|
- });
|
|
|
+ return text.replace(/[&<>"']/g, (s) => entityMap[s]);
|
|
|
}
|
|
|
|
|
|
export { Text as default, escapeText };
|