avdgaag / typogruby

Improves web typography like Django's Typogrify
http://avdgaag.github.com/typogruby
MIT License
51 stars 9 forks source link

Add hairspace typographic improvement. #12

Closed bobthecow closed 12 years ago

bobthecow commented 13 years ago

Em dashes should be set apart from adjacent characters by hairspaces. hairsp will apply this rule, but only to em dash entities (—, — and &#x2014) which are surrounded by one or more spaces, or by non-breaking space.

e.g. "foo — bar" is converted into "foo — bar", and there is great rejoicing.

It also works with numeric and hex representations of em dashes: — and —, respectively.

Note that IE 6 doesn't play nice with hairspaces (or so I've heard), so I didn't add this to the default improve method. If you really need to support IE 6 users, don't use hairspaces :)

It's best to apply this filter after RubyPants so you can pick up the -- conversions, so it should be used like this: hairsp(improve(text)).

avdgaag commented 13 years ago

Hm, not all browsers support these characters, so we indeed cannot activate it by default. But if it is not, and it requires a special action to apply (rather than using just improve), do you guess it would ever be used?

It seems to me this sort of thing would be better implemented with javascript on the client side… Could there be an easier way to enable or disable this filter?

I don't like Typogruby.hairsp(Typogruby.improve(text)), but something like Typogruby.enable_unicode.improve(text) or Typogruby.improve_unicode(text) might work. That also leaves room for further typographic enhancements that are not supported by older browsers, without having to know all the filter names to apply (let alone the order).

What do you think?