An adaptation idea might be to allow regular expression instead of start/end strings to identify blocks.
<script language='javascript'>
function toggle(id){
a = document.getElementById("a_"+id);
if (a.innerHTML == '+'){
document.getElementById("fold_"+id).style.display="block";
a.innerHTML="-";
} else {
document.getElementById("fold_"+id).style.display="none";
a.innerHTML='+';
}
}
</script>
<?php
function parsefold($f,$start="<block>",$end="</block>",$show=true){
$nest = array();
$l = strlen($f);
$id = 0;
$o = '';
$skip = 0;
for ($p = 0; $p < $l; $p++){
if (substr($f,$p,strlen($start)) == $start){
array_push($nest,$id);
$o .= $show ? $start : '';
$o .= "<font color='#0066ff'><b>[<a style='cursor: crosshair;' id='a_$id' onclick='toggle($id);'>+</a>]</b></font>";
$o .= "<div style='margin-left: " . (sizeof($nest)*16) . "px; display: none;' id='fold_$id'>";
$id++;
$skip += (strlen($start)-1);
}
elseif (substr($f,$p,strlen($end)) == $end){
$cid = array_pop($nest);
$o .= "</div>";
$o .= $show ? $end : '';
$skip += (strlen($end)-1);
}
else {
if ($skip > 0){
$skip--;
} else {
$o .= substr($f,$p,1);
}
}
}
return $o;
}
?>
loading
