wysi-not-wyg/living with their lies

published on:
September 14, 2010
comments

No matter how carefully your templates are constructed, no matter how meticulous your css is planned, once a wysiwyg (what you see is what you get) editor enters the game you're pretty much fucked. With the rise of the CMS the wysiwyg editor tagged along and became a commodity in web-design, royally screwing up user-generated content on a website near you. There aren't too many good alternatives though, so we'll just have to try and live with it for the time being.

you don't get what you see

There is nothing particularly wrong with the concept of wysiwyg, in fact it helps clients to make the content they are entering into the system less abstract. They can see the impact of what they are writing in real-time which is a big advantage to them. The problem though is that concept and reality are often miles apart from each other, pretty much nullifying the advantages wysiwyg is supposed to bring them.

The best way to incorporate a wysiwyg editor is as an in-page editor. By giving the component a subtle yet recognizable look you'll be able to mimic the actual appearance of the content. Important is to make sure the width of the wysiwyg is equal to the actual content area and to transfer all the appropriate content styles (fe line-height, font size and color, ...). If the actual content area is just a few pixels wider than the wysiwyg editor it could already mess up some carefully constructed content. Mostly though wysiwyg editors are used for back-end editing. This makes it a lot harder to display the editor at the appropriate size with all the correct styles applied to the content, let alone imagine the content in its actual context.

All of that is just about what you can see on screen. What you get is actually a lot worse. The wysiwyg editors generate their own html in the background. In theory a good thing as it generates headings, paragraphs and list items (semantics!) but the reality is not as nice as they'll make it out to be. Especially when removing content the editors often leave behind empty tags and crappy html poo, sometimes even invalidating your html code. Depending on the css you've written, this could become problematic.

cuff your clients

Those in charge of sales love wysiwyg because of its many possibilities and features. Clients can change the font, color and styling of the text. They can insert images, lists and headings, they can even build their own content table. And best of all, it's not you who has to do all the hard work, the client can do so himself. Many forget that by working like this you're effectively turning the client into a web master, a job often not suitable for them.

The more possibilities you give a client, the more ways he will find to screw things up. You can talk hours about company styles and guidelines, but give them the option to mess around with fonts and colors and before you know your carefully constructed site is filled with bold, italic purple text in some or other exotic font. And that's only if you're lucky, Comic Sans is probably a more realistic example.

Leaving options like changing colors and fonts in is usually not a good idea. Most wysiwyg editors allow you to tweak its capabilities one by one but only rarely is an editor tweaked to leave just the necessary tools. It still doesn't guarantee that clients won't find other ways to mess things up (they are quite inventive when they need be), but at least it closes down some very obvious doors.

so what can we do

As much as you'd like to prevent the problem rather than curing it, you'll find yourself more than once confronted with issues originating from wysiwyg content. There isn't a whole lot you can do about them (apart from entering the back-end and manually editing the content yourself), but there are a few tricks you can learn.

mark wysiwyg content sections

Be it through the use of an extra class or by adding a structural element, just make sure that you can safely identify wysiwyg content. It will come in handy when applying specific css fixes and it can also be used to remove leftover or unwanted html elements with javascript (think font or center tags). Trust me, it's worth the trouble of adding the extra html element.

countering the br element

br {display:block; height:1px;}

This can be a little dangerous, depending on the nature of your client. The br element is often used to create fake paragraphs, by applying the above style it will be much harder to do so while at the same time preserving the original function of the br, namely starting a new line without starting a new paragraph of text. Just make sure you don't end up with 24 consecutive br elements simply to create a 24px gap between the text.

It's a shame nothing similar exists to counter consecutive   entities, but those are a part of the content itself. If you must though, I guess a little javascript could do the trick here.

removing empty elements

p:empty (,..) {display:none; visibility:hidden;}

Another little trick is to use the :empty pseudo-class to hide empty elements from view. Any tags left by the wysiwyg editor will be completely hidden, making sure that none of the css on these elements will mess up your layout (padding is a notorious annoyance in this case). This won't work in older browsers but at least you're doing something for the others.

Alternatively you can use javascript again to filter out these elements as a fall-back for the less capable browsers. This could cause the layout to jump a little though (depending on the css which is applied) so I still prefer the css option as a standard.

be creative

And that's about all I've got so far. If you have any more tips or tricks, please do share. For a long time I've ignored the issues of wysiwyg content but I think it's about time to get rid of the most glaring issues. Other alternatives (like wyisywym - mean) are simply not as user-friendly or advanced as the current wysiwyg editors, so I'm sure we'll just have to deal with them for now.

With the pointers above though I'm sure you'll be able to counter the most common issues, or at least have a solid base to start countering them.

Comments

Mathias

comment number
date
September 14, 2010 12:05

No matter how carefully your templates are constructed, no matter how meticulous your css is planned, once a wysiwyg (what you see is what you get) editor enters the game you're pretty much fucked.

So true. This is exactly why QMS (intentionally) doesn't have a WYSIWYG editor. Most clients don't understand HTML, so content management systems shouldn't force them to deal with it.

The CSS patches you propose are interesting, but really — these things should be handled by the back-end, preferably by using a whitelist of allowed tags and attributes.

Rob Hofker

comment number
date
September 14, 2010 13:32

Absolutely true. These wysiwyg editors are beautiful, but usually don't show the styling that will displayed in the end and also allow the use of tags you don't want to be used. The patches are clever, but I think that you always need some form of clearing process in the backend to remove unwanted tags. Good article.

Niels Matthijs

comment number
date
September 14, 2010 13:43

I absolutely agree with implementing a back-end filter, but some situations call for quicker and more independent action. Sometimes you (meaning the front-end guy) are the only one standing between the problem and the fix, and usually these situations call for atypical measures. I guess that's when the above pointers will come in handy :)

Bobby Jack

comment number
date
September 20, 2010 18:19

Just make sure you don't end up with 24 consecutive br elements simply to create a 24px gap between the text.

Actually, in FF (3.6) this doesn't appear to be an issue: 24 BRs creates no more space than a single BR. What DOES happen is that a single BR prevents margin collapsing between paragraphs. It looks like:

p + br { margin-bottom: -1em; } /* Or whatever your para's margin is */

might help, but other block-level elements need to be taken into account, and this is all getting quite fiddly!

Niels Matthijs

comment number
date
September 21, 2010 08:19

Hmmm, pretty interesting though I'm not sure how rendering-legal that is. A br-element is supposed to force a new line, so I would assume it should do just that.

I wonder if FF3.6 does a similar thing with successive nbsp; entities ...

Bobby Jack

comment number
date
September 21, 2010 11:25

It seems to treat BR elements very strangely. The 'display: block, height: 1px' trick appears to have the effect of completely hiding them. Even applying other styles (large height, width, border) has no effect on the rendering (although Firebug shows 'interesting' results which are difficult to describe!)

I'm wondering if FF is treating BRs as, effectively, replaced content (maybe they are) and, therefore, styling is ... weird! :)

Kenya

comment number
date
July 22, 2011 06:14

The wysiwyg info is great for us who run busy blogs.

* required fields

Leave your data
Leave a comment