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 b213e10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ jobs:
change:feature
change:documentation
change:chore
change:refactor
add_comment: false
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 b213e10

Please sign in to comment.