memo.xight.org

日々のメモ

WordPressの 改行 -> <br>タグ 変換

Summary

  勝手に改行を<br>タグに変換するので,やたら空行が目立つ.

解決!

/path/to/xoops/modules/wordpress/wp-includes/functions-formatting.php を変更

preg_replace でタグを置換している箇所に ignore case を付加
58-81行目
function wpautop($pee, $br = 1) {
	$pee = $pee . "\n"; // just to make things a little easier, pad the end
	$pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); // Space things out a little
	$pee = preg_replace('!(<(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!i',"\n$1", $pee);
	$pee = preg_replace('!(</(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])>)!i',
"$1\n", $pee);
	$pee = preg_replace("/(\r\n|\r)/", "\n", $pee); // cross-platform newlines
	$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
	$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t<p>$1</p>\n",$pee); // make paragraphs, including one at the end
	$pee = preg_replace('|<p>\s*?</p>|i', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
	$pee = preg_replace('!<p>\s*(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>!i',"$1", $pee); // don't pee all over a tag
	$pee = preg_replace("|<p>(<li.+?)</p>|i", "$1", $pee); // problem with nested lists
	$pee = preg_replace('|<p><blockquote([^>]*)>|i',"<blockquote$1><p>", $pee);
	$pee = str_replace('</blockquote></p>', '</p></blockquote>',$pee);$pee);
	$pee = preg_replace('!<p>\s*(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!i',"$1", $pee);
	$pee = preg_replace('!(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>!i',"$1", $pee);
	if ($br) $pee = preg_replace('|(?<!<br />)\s*\n|i', "<br />\n",$pee); // optionally make line breaks
	$pee = preg_replace('!(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*<br/>!i', "$1", $pee);
	$pee = preg_replace('!<br/>(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!i', '$1', $pee);
	$pee = preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&#038;$1',$pee);
	$pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', "stripslashes('$1') .  clean_pre('$2')  . '</pre>' ", $pee);

	return $pee;
}


Patch

functions-formatting.phpのパッチ

Reference

  WordPress Japan - 改行のBR変換について
  http://phpbb.xwd.jp/viewtopic.php?p=990