Recognizing bold font-weights on paste
authorAlexander Ebert <ebert@woltlab.com>
Mon, 23 Jan 2017 12:57:33 +0000 (13:57 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 23 Jan 2017 12:57:39 +0000 (13:57 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 0e5472396ab351470b61be98aa6dd6eada372a7d..4678855fabbd96bb6cfc11be7fcf514baf96fe03 100644 (file)
@@ -129,7 +129,7 @@ $.Redactor.prototype.WoltLabClean = function() {
                                var div = elCreate('div');
                                div.innerHTML = html.replace(/@@@WOLTLAB-P-ALIGN-(?:left|right|center|justify)@@@/g, '');
                                
-                               var element, elements = elBySelAll('[style]', div), property, removeStyles;
+                               var element, elements = elBySelAll('[style]', div), property, removeStyles, strong, styleValue;
                                for (var i = 0, length = elements.length; i < length; i++) {
                                        element = elements[i];
                                        
@@ -139,6 +139,21 @@ $.Redactor.prototype.WoltLabClean = function() {
                                                
                                                //noinspection JSUnresolvedVariable
                                                if (this.opts.woltlab.allowedInlineStyles.indexOf(property) === -1) {
+                                                       if (property === 'font-weight') {
+                                                               styleValue = element.style.getPropertyValue(property);
+                                                               if (styleValue === 'bold' || styleValue === 'bolder') {
+                                                                       styleValue = 600;
+                                                               }
+                                                               
+                                                               styleValue = ~~styleValue;
+                                                               if (styleValue > 500) {
+                                                                       // treat anything above 500 as bold
+                                                                       strong = elCreate('strong');
+                                                                       element.parentNode.insertBefore(strong, element);
+                                                                       strong.appendChild(element);
+                                                               }
+                                                       }
+                                                       
                                                        removeStyles.push(property);
                                                }
                                        }