Skip to content
Permalink
Browse files

Improved - addBreaks()

行末がブロックレベル要素の場合は改行を付加しない
<table>
<ul>
など
  • Loading branch information...
yama committed Apr 1, 2015
1 parent af1a4d4 commit 4e700900a278bc53ee089fbd8286bf2967915ec9
Showing with 24 additions and 2 deletions.
  1. +24 −2 nucleus/libs/globalfunctions.php
@@ -1188,8 +1188,30 @@ function isValidSkinName($name) {
}
// add and remove linebreaks
function addBreaks($var) {
return nl2br($var);
function addBreaks($text) {
// if($mode==='nl2br') return nl2br($text);
$text = str_replace(array("\r\n","\r"),"\n",$text);
$blockElms = 'br,table,tbody,tr,td,th,thead,tfoot,caption,colgroup,div';
$blockElms .= ',dl,dd,dt,ul,ol,li,pre,select,option,form,map,area,blockquote';
$blockElms .= ',address,math,style,input,p,h1,h2,h3,h4,h5,h6,hr,object,param,embed';
$blockElms .= ',noframes,noscript,section,article,aside,hgroup,footer,address,code';
$blockElms = explode(',', $blockElms);
$lines = explode("\n",$text);
$c = count($lines);
foreach($lines as $i=>$line)
{
$line = rtrim($line);
if($i===$c-1) break;
foreach($blockElms as $block)
{
if(preg_match("@</?{$block}" . '[^>]*>$@',$line))
continue 2;
}
$lines[$i] = "{$line}<br />";
}
return join("\n", $lines);
}
function removeBreaks($var) {

0 comments on commit 4e70090

Please sign in to comment.
You can’t perform that action at this time.