Skip to content

Commit

Permalink
Avoid unnecessary local map creations
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jul 19, 2024
1 parent 5d752e3 commit b941da3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/quill/src/blots/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { TextBlot } from 'parchment';

class Text extends TextBlot {}

// https://lodash.com/docs#escape
const entityMap: Record<string, string> = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
};

function escapeText(text: string) {
return text.replace(/[&<>"']/g, (s) => {
// https://lodash.com/docs#escape
const entityMap: Record<string, string> = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
};
return entityMap[s];
});
return text.replace(/[&<>"']/g, (s) => entityMap[s]);
}

export { Text as default, escapeText };

0 comments on commit b941da3

Please sign in to comment.