I have some JavaScript code that transforms dumb quotes into smart quotes in a contenteditable
.
The problem appears when you add dumb quotes at the beginning of the line they only close. For example you get this:
”dumb quotes” instead of “dumb quotes”
Try out the demo: http://jsfiddle.net/7rcF2/
The code I’m using:
function replace(a) {
a = a.replace(/(^|[-\u2014\s(\["])'/g, "$1\u2018"); // opening singles
a = a.replace(/'/g, "\u2019"); // closing singles & apostrophes
a = a.replace(/(^|[-\u2014/\[(\u2018\s])"/g, "$1\u201c"); // opening doubles
a = a.replace(/"/g, "\u201d"); // closing doubles
a = a.replace(/--/g, "\u2014"); // em-dashes
return a };
Any ideas? Thanks!
P.S. I suck at regular expressions…