(A great place to start if you're new here is my Wide Spacing Roadmap.)

Thursday, April 18, 2013

Spacing in Twitter (a small victory)

I tweeted this back in January to twitter's feature suggestions account:

Wide Spacer @WideSpacer 05 Jan 13
@features Please change the CSS for tweet text: set white-space to pre-wrap. With only 140 chars, if people use two spaces they mean it.
(The short answer is that sometime recently they have done exactly this.)

There was more going on than just the wishful thinking.  In fact many twitter clients, particularly those widely used on mobile platforms, already preserved both the spaces and the newlines in tweets.  So users of those clients could "format" their tweets with extra spaces and new-lines, and often did.  But on, these formatting efforts were lost to HTML's default behavior of treating all new-lines as blank spaces, and of combining multiple spaces into a single space.

HTML doesn't do this because it hates spaces, or because it has taken sides in the debate on sentence spacing.  HTML was originally based on SGML, a markup language for adding meta information (like formatting instructions) to plain text.  In SGML's view of the world, spaces are not content.  They simply serve to separate words from each other.  One space does this just as well as ten spaces.  If there's any formatting to be done, that should be in a tag as meta information.

Of course HTML has never added any explicit formatting capability for sentence spacing (although there are plenty of workarounds, most of them cumbersome).  But HTML has always had a <pre> tag, which means the contents of the tag are pre-formatted, and no formatting should be done; the original spacing and new-lines should be displayed.

As the web progressed, and CSS became the standard way of doing things, a CSS property called "white-space" was added.  This property describes how spaces and new-lines should be interpreted.  The possible settings include "normal", which means the way HTML has always done things, and "pre" which means the text should behave just as it would inside a <pre> section.  It also includes the setting "pre-wrap" which is alot like "pre" except that lines are wrapped both as needed, and also on new-line characters.

The pre-wrap setting is perfect for twitter, where it will preserve the user's original spacing as much as possible, but still wrap lines as needed to fit into the available space.

(Also note that there's an obvious missing feature from "white-space": there is no setting which honors multiple spaces, but ignores new-lines.  This would be handy for people who have been writing HTML in some traditional editors where long lines that wrapped are inconvenient, e.g. the traditional UNIX "vi" visual editor.  They may want to preserve spacing but not the new-lines.)

A few weeks ago I began noticing that tweets on were appearing showing user formatting.  A quick look showed that they had indeed changed their white-space property for tweet text to "pre-wrap".  So now tweeters can add their wide spacing and it will actually display properly for the majority of twitter users.

This also means the next time there's a twitter debate about sentence spacing, the monospacers won't be able to say "yeah but why doesn't your tweet have wide sentence spacing?"  Because now it will.

Thank you Twitter!

No comments:

Post a Comment

Comments on older posts require moderation.