text2html formatter support raw <html> sections

This commit is contained in:
mappu 2014-06-08 20:07:24 +12:00
parent 79c07edb4d
commit a87bfdf687

View File

@ -96,6 +96,8 @@ function hesc($sz) {
}
function text2html($sz) {
$sectionFmt = function($sz) {
$base = hesc($sz);
$base = preg_replace('~=+(.+)=+~', '<strong>\\1</strong>', $base);
@ -110,6 +112,34 @@ function text2html($sz) {
}
return nl2br($base);
};
$identity = function($sz) {
return $sz;
};
$splitInside = function($begin, $end, $sz) {
$parts = explode($begin, $sz);
if (count($parts) == 1) return [$sz];
$ret = [$parts[0]];
foreach($parts as $part) {
$inner = explode($end, $part, 2);
$ret = array_merge($ret, $inner);
}
return $ret;
};
$oddEven = function(array $parts, $odd, $even, $join='') {
$ret = [];
for($i = 0, $e = count($parts); $i != $e; ++$i) {
$ret[] = ($i % 2) ? $odd($parts[$i]) : $even($parts[$i]);
}
return implode($join, $ret);
};
$htmlSections = $splitInside('<html>', '</html>', $sz);
return $oddEven($htmlSections, $sectionFmt, $identity);
}
function array_decimate($array, $total, $partno) {