talideon.com

Blackout Ireland

March 17, 2006 at 8:18PM Converting typewriter quotes to proper typographer’s quotes

Here’s how to do it in a nice clean way that works in everything from ColdFusion 5 and on:

function MagicQuote(txt) {
    var prefix = "(^|[ " & Chr(9) & Chr(10) & Chr(13);

    // Left quotes
    txt = REReplace(txt, prefix & "'])""",        "\1&##8220;", "ALL");
    txt = REReplace(txt, prefix & "]|&##8220;)'", "\1&##8216;", "ALL");

    // Right quotes
    txt = Replace(txt, """",        "&##8221;",  "ALL");
    txt = Replace(txt, "'&##8220;", "'&##8221;", "ALL");
    txt = Replace(txt, "'",         "&##8217;",  "ALL");

    return txt;
}