Skip to content

Commit

Permalink
Fix: Font with spaces and numbers #1382
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Apr 23, 2024
1 parent 3305253 commit 82714be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/plugins/submenu/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ let s2 = window.s2 = suneditor.create(document.getElementById('editor2'), {
html: '<p>Template 1</p>'
}
],
// 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',
Expand Down

0 comments on commit 82714be

Please sign in to comment.