Browse Source

fix nesting <span> and <li>

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@463 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 15 years ago
parent
commit
51cfc2b083
  1. 27
      coverager/coverager.php

27
coverager/coverager.php

@ -107,7 +107,11 @@ class XcacheCoverageViewer
$source = implode('', $lines);
ob_start();
highlight_string($source);
$lines = explode('<br />', str_replace("\n", "", ob_get_clean()));
$lines = str_replace("\n", "", ob_get_clean());
$lines = str_replace('<code>', '', $lines);
$lines = str_replace('</code>', '', $lines);
$lines = preg_replace('(^<span[^>]*>|</span>$)', '', $lines);
$lines = explode('<br />', $lines);
$last = array_pop($lines);
$filecov = sprint_cov($fileinfo['cov'], $lines, false);
$filecov .= $last;
@ -294,11 +298,31 @@ class XcacheCoverageViewer
function sprint_cov($cov, $lines, $encode = true)
{
$lastattr = null;
foreach ($lines as $l => $line) {
$offs = $l + 1;
if ($encode) {
$line = str_replace("\n", "", htmlspecialchars($line));
}
else if ($line !== "") {
if (substr($line, 0, 7) == '</span>') {
$lastattr = null;
$line = substr($line, 7);
}
else if (isset($lastattr)) {
$line = $lastattr . $line;
}
if (preg_match('!(<span[^>]+>|</span>).*$!', $line, $m)) {
if ($m[1] == '</span>') {
$lastattr = null;
}
else {
$line .= '</span>';
$lastattr = $m[1];
}
}
}
if (isset($cov[$offs])) {
$lines[$l] = sprintf("<li class=\"line%sCov\"> %s\t%s\n</li>"
, $cov[$offs] ? '' : 'No'
@ -311,6 +335,7 @@ function sprint_cov($cov, $lines, $encode = true)
}
return implode('', $lines);
}
if (!function_exists('xcache_coverager_decode')) {
function xcache_coverager_decode($bytes)
{

Loading…
Cancel
Save