以前就有朋友反应过日志中的代码中引号有问题,一直也没放在心上。今天仔细看了一下,原来wordpress会自动把blockquote中的半角引号转换成全角引号。以下是两种解决方法

修改formatting.php文件

wordpress对日志的格式化处理代码保存在includes文件夹下的formatting.php文件中。用文本编辑器打开该文件,找到以下代码片段

if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0}
amp;& empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) {
// This is not a tag, nor is the texturization disabled
// static strings
$curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions
$curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
}

注释掉两条$curl语句即可,修改后代码如下:

if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0}
&& empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) {
// This is not a tag, nor is the texturization disabled
// static strings
//$curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions
//$curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
}

还是修改formatting.php文件

同样是修改formatting.php文件,上面提到的代码可以不用注释掉,找到下面这行代码

$default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');

改为

$default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt', 'blockquote');

也就是在$default_no_texturize_tags中加入一个’blockquote’标签

不使用blockquote

以上两种方法都可以解决引号转换的问题,不过需要修改wordpress的源代码,对以后的升级带来了麻烦。从上面的代码中我们也可以看到,像pre,code这些标签都不会转换引号,可以使用这两个标签来代替blockquote。

添加评论

1 条评论

  1. 1 F

    howtoquickweightloss

    2011-04-07 星期四 18:42

    文章相当有用 正在了解怎么修改formatting.php

    回复

添加评论