text.js 382 B

12345678910111213141516171819
  1. import { TextBlot } from 'parchment';
  2. class Text extends TextBlot {}
  3. function escapeText(text) {
  4. return text.replace(/[&<>"']/g, s => {
  5. // https://lodash.com/docs#escape
  6. const entityMap = {
  7. '&': '&amp;',
  8. '<': '&lt;',
  9. '>': '&gt;',
  10. '"': '&quot;',
  11. "'": '&#39;',
  12. };
  13. return entityMap[s];
  14. });
  15. }
  16. export { Text as default, escapeText };