There are three kinds of lies: lies, damned lies and statistics.
–Mark Twain
青春只有一次,请不要绕行!
2008-09-25 19:44:30

消灭 WordPress 里的全角单引号

@ mikel   类别: 二进制码

拷贝网页和代码很窝火的事情之一是,好好的单引号 ' 和双引号 " 硬是被转义成 ’ (& #8217,右单引号) 和 ” (& #8221,右双引号),本来这也没什么,但是在中文系统下这俩就被显示成了全角的单引和双引,于是常常不得不郁闷地全文替换。

不幸的是,WordPress 也喜欢这么做,导致英文字母们和代码们看起来好好的,一拷贝,就发现里面大量难看的引号们。

不过改起来也很简单。我知道我习惯非常不好,喜欢直接改源代码,但是毕竟方便嘛。

WP 安装目录下 wp-includes/formatting.php

———

16 $cockney = array("'tain't", "'twere", "'twas", "'tis", "'twill", "'til", "'bout", "'nuff", "'round", "'cause");
17 $cockneyreplace = array("’tain’t", "’twere", "’twas", "’tis", "’twill", "’til", "’bout", "’nuff", "’round", "’cause");

这是给缩写字作美化,不需要,改为空值:

16 $cockney = array();
17 $cockneyreplace = array();

———

20 $static_characters = array_merge(array('---', ' -- ', '--', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
21 $static_replacements = array_merge(array('—', ' — ', '–', 'xn--', '…', '“', '’s', '”', ' ™'), $cockneyreplace);

大多数无所谓,看个人喜好了。但有关引号的那两个还是删掉吧

20 $static_characters = array_merge(array('---', ' -- ', '--', 'xn–', '...', '``', ' (tm)'), $cockney);
21 $static_replacements = array_merge(array('—', ' — ', '–', 'xn--', '…', '“', ' ™'), $cockneyreplace);

———

23 $dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|")\'/', '/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/');
24 $dynamic_replacements = array('’$1','$1‘', '$1″', '$1′', '$1’$2', '$1“$2', '”$1', '’$1', '$1×$2');

除了最后一个,,,全都不要了,话说正则表达式看着真头痛

23 $dynamic_characters = array('/(\d+)x(\d+)/');
24 $dynamic_replacements = array('$1×$2');

// wordpress 2.3.2


Tags: ,

相关文章

关于 “消灭 WordPress 里的全角单引号”已有1条评论

  1. 1
    Kay 冒了个泡: @2008-09-28,  11:08:59 

    好汉……

评论 RSS Feed。 TrackBack URI

发表评论