Random ...
 
December 2017
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Tags ...
Links



python+zope++:: Not so smart quotes
Posted at 10.Apr,2007 12:45  Comments 0 / Trackbacks 0 / Like this post!
Technorati tag(s):

Ever had that problem where you copy from word, notepad, and paste to your html form, submit and get nasty characters rendered? Well, at least in IE?

That's smart quotes for you. It's not in ISO-8859-1 and won't be rendered correctly. It's just a touched up character, e.g the left apostrophe.

Here's a python script that will replace all smat quotes with its relevatn html entity, adapted from here

   def convNotSoSmartQuotesToHtmlEntity(x):
     d=      {  "\xc2\x82":"‚",
                "\xc2\x83":"ƒ",
                "\xc2\x84":"„",
                "\xc2\x85":"…",
                "\xc2\x86":"†",
                "\xc2\x87":"‡",
                "\xc2\x88":"ˆ",
                "\xc2\x89":"‰",
                "\xc2\x8A":"Š",
                "\xc2\x8B":"‹",
                "\xc2\x8C":"Œ",
                "\xc2\x91":"‘",
                "\xc2\x92":"’",
                "\xc2\x93":"“",
                "\xc2\x94":"”",
                "\xc2\x95":"•",
                "\xc2\x96":"–",
                "\xc2\x97":"—",
                "\xc2\x98":"˜",
                "\xc2\x99":"™",
                "\xc2\x9A":"š",
                "\xc2\x9B":"›",
                "\xc2\x9C":"œ"}
      for i in d.keys():
         x=x.replace(i,d[i])
      return x

I'm sure there's a better way of doing this. If so, do tell.

This was done in a few minutes, so sue me :).


Bookmark and Share

Is this entry helpful? Comments/Donate/Click some google ads.  
Trackback is http://myzope.kedai.com.my/blogs/kedai/128/tbping 

Comments
Post a comment