symphonycms2-extensions / richtext_redactor

Rich Text Formatter implementation for Symphony CMS using RedactorJS
Other
5 stars 8 forks source link

Unscrupulous <span> tags - can we prevent them? #14

Open nathanhornby opened 10 years ago

nathanhornby commented 10 years ago

These really wind me up - for pretty much no reason whatsoever I quite regularly find that Redactor has wrapped bits of text in span tags that contain inline styles for font size and line height. This can be triggered by all sorts of things, none of them warranted.

I have a feeling this will be a fault in Redactor itself (maybe even fixed as this extension seems to be, very unfortunately, unmaintained).

If anyone knows of a way we can stop these completely unwanted span tags from appearing I'd be hugely grateful. I can live with the odd <br/> and &nbsp;, but the spans can cause issues in the front-end (why would you ever want your WYSIWYG controlling line-height?? Madness).

johnpuddephatt commented 9 years ago

From imperavi.com/redactor/log/:

Version 9.0.0 May 30, 2013: Fixed garbage span tags in Chrome и Safari.

Like you say, it's unfortunate the extension isn't being maintained :(

johnpuddephatt commented 9 years ago

The issue is documented here, with a fix. I've tested the patch and it appears to work without issue.

I added the below method to redactor.min.js:

checkForSpan: function() {
            this.$editor.on("DOMNodeInserted", $.proxy(function(e) {
                if (e.target.tagName == "SPAN") {
                    var helper = $("<b>helper</b>");
                    $(e.target).before(helper);
                    helper.after($(e.target).contents());
                    helper.remove();
                    $(e.target).remove();
                }
            }, this));
        }

And added this.checkForSpan() within the formatNewLine method.