From 82714beb2c1aff5d91e026351a5f1764923032b4 Mon Sep 17 00:00:00 2001 From: Yi JiHong <0125ses@hanmail.net> Date: Tue, 23 Apr 2024 22:46:17 +0900 Subject: [PATCH] Fix: Font with spaces and numbers #1382 --- src/plugins/submenu/font.js | 7 +++++-- test/dev/suneditor_build_test.js | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/submenu/font.js b/src/plugins/submenu/font.js index 83a8f63f9..eb73c1f32 100644 --- a/src/plugins/submenu/font.js +++ b/src/plugins/submenu/font.js @@ -88,7 +88,7 @@ export default { if (currentFont !== fontContext.currentFont) { for (let i = 0, len = fontList.length; i < len; i++) { - if (currentFont === fontList[i].getAttribute('data-value')) { + if (currentFont === (fontList[i].getAttribute('data-value') || '').replace(/'|"/g, '')) { this.util.addClass(fontList[i], 'active'); } else { this.util.removeClass(fontList[i], 'active'); @@ -105,10 +105,13 @@ export default { e.preventDefault(); e.stopPropagation(); - const value = e.target.getAttribute('data-value'); + let value = e.target.getAttribute('data-value'); if (value) { const newNode = this.util.createElement('SPAN'); + if (/[\s\d\W]/.test(value) && !/^['"].*['"]$/.test(value)) { + value = '"' + value + '"'; + } newNode.style.fontFamily = value; this.nodeChange(newNode, ['font-family'], null, null); } else { diff --git a/test/dev/suneditor_build_test.js b/test/dev/suneditor_build_test.js index 9f7cfde87..4761204d1 100644 --- a/test/dev/suneditor_build_test.js +++ b/test/dev/suneditor_build_test.js @@ -1027,6 +1027,7 @@ let s2 = window.s2 = suneditor.create(document.getElementById('editor2'), { html: '
Template 1
' } ], + // font: ['\'Exo 2\'', 'Sans-serif', 'Exo 2'], imageGalleryUrl: 'https://etyswjpn79.execute-api.ap-northeast-1.amazonaws.com/suneditor-demo', // addTagsWhitelist: "fld|sort|sortType|lst|lstfld|header|section", lineAttrReset: 'class',