【发布时间】:2013-01-31 04:34:41
【问题描述】:
我有一些 JavaScript 代码可以将 contenteditable 中的哑引号转换为智能引号。
当您在仅关闭的行的开头添加哑引号时,就会出现问题。例如你得到这个:
”dumb quotes” instead of “dumb quotes”
试用演示:http://jsfiddle.net/7rcF2/
我正在使用的代码:
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 };
有什么想法吗?谢谢!
附注我很讨厌正则表达式……
【问题讨论】:
标签: javascript html replace quotes