Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Fixing quotes with Javascript

Marek Prokop has a cunning way of getting Internet Explorer to style <abbr> elements (IE, for reasons unknown, usually ignores their existence both as stylable elements and through the DOM). A comment by Mr. Farlops on diveintomark inspired me to have a go at fixing IE’s equally faulty quotes behaviour using javascript. Rather than detecting IE by checking for the presence of document.all, I decided to use a Microsoft specific proprietary extension: DHTML Behaviors.

The HTC file (fixquotes.htc)looks like this:

<public:attach event="oncontentready" onevent="init();" />
<script>
function init() {
  element.innerHTML = '&#8220;'+element.innerHTML+'&#8221;';
}
</script>

The additional CSS required to use it (and to make quotes look pretty in better browsers), based on Mark Pilgrim’s code from The Q tag, looks like this:

q {
  behavior: url(fixquotes.htc);
  quotes: '\201C' '\201D' '\2018' '\2019';
}
q:before {
  content: open-quote;
}
q:after {
  content: close-quote;
}

There are two main disadvantages to this solution: It introduces an invalid property to your CSS, and it could result in duplicated quotes in IE 7 should that browser finally fix the lack of quote element support.

Mark Pilgrim advocates using a server side script to mark up quotations with the relevant HTML entities. I’m not too keen on this solution purely because I tend to surf the web using Lynx 2.7 from University every now and then, and Lynx 2.7 displays some entities untranslated resulting in sites looking like this:

   The guy in charge of &#8220;doing techie stuff for The Register&#8221;
   emailed me today to say that The Register is now sporting a shiny new
   RSS 1.0 feed. It validates and everything. Woohoo! Guess I&#8217;ll
   have to find somebody else to pick on now. [winking face]

(This issue is fixed in Lynx 2.8).

Time for bed, said Zebedee.

This is Fixing quotes with Javascript by Simon Willison, posted on 3rd April 2003.

View blog reactions

Next: css-discuss archives back online

Previous: Mozilla changes focus

9 comments

  1. Hm. Your excerpt thing decides to show the content of my pingback a bit out of context and make it look like I'm slagging you off, which I'm not :) I did actually write most of what I posted as a comment here, but your site kept complaining that I was using invalid XHTML (when I hadn't written, like, any XHTML), so I made it into a post.

    Stuart Langridge - 3rd April 2003 19:35 - #

  2. Lynx 2.8 was released in 1999. Lynx 2.7 is almost as old as Netscape 4.0. Time to upgrade!

    Mark - 3rd April 2003 19:41 - #

  3. Time for another of my "please upgrade X" emails to the University server admins then... so far they've ignored 4 out of 4.

    Simon Willison - 3rd April 2003 19:49 - #

  4. Gosh, shucks! I'm rather stunned and embarrassed. I make a modest suggestion about using something like Mr. Prokop's hack to fix IE's bad implementation of the Q tag on Mr. Pilgrim's site and suddenly a legion of site geeks take a swing at it. I am grateful and humbled! Ain't the Internet cool? I also spoke with Mr. Prokop by e-mail just yesterday and he did mention that the idea did occur to him right after he had the idea of using script to fix ABBR, but he immediately saw a few problems with it: 1) What to do with nested quotes? 2) The script mechanically swaps in language specific special entities for quotes. This means that Czech quotes won't look right to English users and vice versa.

    Mr. Farlops - 4th April 2003 05:25 - #

  5. Nested quotes work OK, but I hadn't thought of the language issue. I suppose that could be resolved manually using separate fixquotes.htc files - fxquotes.cz.htc, fixquotes.en-gb.htc etc.

    Simon Willison - 4th April 2003 08:52 - #

  6. Sadly, what you *actually* need to do here is parse the "quotes" bit in the CSS, which, after all, is supposed to specify which quotes to use. I admit that there's a problem with knowing which ones the browser will apply by default (in the absence of specification in CSS), which I imagine is dependent on the locale of the page? Some testing required.

    Stuart Langridge - 4th April 2003 11:18 - #

  7. Lynx 2.8 may have been released in 1999, but 2.8.3 is the current version nonetheless: http://lynx.browser.org So we're not actually living in the past, Mark.

    Joe Clark - 4th April 2003 20:38 - #

  8. What makes you think there will ever be an IE7? Windows Server 2003 (NT 5.2) and Longhorn (NT 6) both still use IE6. I think the only reason Microsoft will start working on IE again is if Gecko based browsers get 15-25% of the market.

    Phillip - 5th April 2003 03:56 - #

  9. Wondering how you might code this solution to work for nested quotes as well? As it is now, if you have a multi-paragraph quote wrapped in an enclosing blockquote tag, your solution results in a quote on a separate line above the first quoted paragraph and another below the last paragraph. It also does not render nested quotes at all. I'm not a Javascript person at all, so just curious if there is a solution to this via JS or the HTC.

    Ron - 12th November 2004 17:16 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/04/03/fixingQuotesWithJavascript

A django site