-
Notifications
You must be signed in to change notification settings - Fork 124
Closed
Description
function dangopress_esc_html($content)
{
if (!is_feed() || !is_robots()) {
$content = preg_replace('/<code(.*)>/i', "<code class=\"prettyprint\" \$1>", $content);
}
$regex = '/(<code.*?>)(.*?)(<\/code>)/sim';
return preg_replace_callback($regex, 'dangopress_esc_callback', $content);
}其中,给code加class的方法过于简单粗暴。如果原来的code中已经有class,就会带来问题。
简单的修改方法为:
function dangopress_esc_html($content)
{
if (!is_feed() || !is_robots()) {
$content = preg_replace('/<code(.*)>/i', "<code class=\"prettyprint\" \$1>", $content);
}
$regex = '/(<code.*?>)(.*?)(<\/code>)/sim';
return preg_replace_callback($regex, 'dangopress_esc_callback', $content);
}
function dangopress_esc_callback($matches)
{
$tag_open = $matches[1];
if ( substr_count($tag_open, "class=") > 1 ){
$tag_open = str_replace(' class="prettyprint" ', " ", $tag_open);
}
$content = $matches[2];
$tag_close = $matches[3];
//$content = htmlspecialchars($content, ENT_NOQUOTES, get_bloginfo('charset'));
$content = esc_html($content);
return $tag_open . $content . $tag_close;
}也就是在dangopress_esc_callback中再修正回来。
Metadata
Metadata
Assignees
Labels
No labels