58 if (isset($contextstack) && is_array($contextstack))
60 $this->contextstack = $contextstack;
61 $this->context = array_pop($contextstack);
62 $this->context->inwhitespace = 0;
67 $this->context->from_language($this->highlightfile, $this->output_module);
68 $this->contextstack =
array();
70 array_push($this->contextstack, $this->context);
71 $this->langstack =
array();
73 if (isset($this->highlightfile->zones))
77 $this->starttags =
array();
78 $this->endtags =
array();
79 $this->starttaglengths =
array();
80 foreach($this->highlightfile->zones as $zone)
82 $this->startmap[$zone[0]] = $zone[2];
83 array_push($this->starttags, $zone[0]);
84 if (!isset($this->endtags[$zone[0]])) $this->endtags[$zone[0]] =
array();
85 array_push($this->endtags[$zone[0]], $zone[1]);
86 $this->starttaglengths[$zone[0]] = strlen($zone[0]);
88 $this->endtaglist =
array();
89 $this->langcache =
array();
94 $arr = preg_split(
"/\n/",
$text);
97 if (isset($this->context->code_parts[0]))
$out.= $this->context->code_parts[0];
98 for ($i=0; $i<$aln; $i++)
101 $this->context->prepro = 0;
103 if ($this->context->preprolength>0 && substr($line, 0, $this->context->preprolength)==$this->highlightfile->prepro)
105 $out.= $this->context->prepro_parts[0];
106 $this->context->prepro = 1;
110 $this->context->inwhitespace = 1;
113 $this->context->incomment = 0;
115 if (isset($this->highlightfile->lineselect) && !$this->context->inselection && substr($line, 0, strlen($this->highlightfile->lineselect))==$this->highlightfile->lineselect)
117 $out.= $this->context->select_parts[0];
118 $line = substr($line, strlen($this->highlightfile->lineselect));
119 $this->context->lineselect = 1;
123 if ($this->highlightfile->notrim==0) $line = trim($line);
128 $sw = $this->
_starts_with($lineorig, $this->highlightfile->unindent);
131 if ($this->context->ind>0 && $sw!=
"")
134 $lineout = str_repeat(
"\t", ($this->context->ind-1));
138 $lineout = str_repeat(
"\t", $this->context->ind);
141 $ln = strlen($lineorig);
142 for ($j=0; $j<$ln; $j++)
144 $currchar = $lineorig[$j];
147 if (isset($this->highlightfile->selecton) && !$this->context->inselection &&
148 !$this->context->inquote && !$this->context->inbcomment &&
149 substr($line, $j, strlen($this->highlightfile->selecton))==$this->highlightfile->selecton)
152 $lineout = $this->
_munge($lineout).$this->context->select_parts[0];
155 $this->context->inselection = 1;
156 $j+= strlen($this->highlightfile->selecton)-1;
160 if (isset($this->highlightfile->selectoff) && $this->context->inselection &&
161 substr($line, $j, strlen($this->highlightfile->selectoff))==$this->highlightfile->selectoff)
164 $lineout.=$this->context->select_parts[1];
167 $this->context->inselection = 0;
168 $j+= strlen($this->highlightfile->selectoff);
173 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->incomment && !($this->highlightfile->perl && $j>0 && $line[$j-1]==
"$"))
177 foreach($this->highlightfile->linecommenton as
$l)
179 if ($l[0] != $currchar)
continue;
180 $lln = $this->context->lcolengths[
$l];
181 if (substr($line, $j, $lln)==$l)
195 $line = substr($line, $j);
196 $lineout = $this->
_munge($lineout);
197 $line = htmlentities($line);
199 if ($this->context->prepro)
201 $out.= $this->context->prepro_parts[1];
202 $this->context->prepro = 0;
204 $out.= $this->context->linecomment_parts[0].$line;
205 if (isset($this->statobj) && $this->statobj->harvest_comments) $this->statobj->comment_cache .=
" ".substr($line, $lncl);
207 $this->context->incomment = 1;
215 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->inbcomment && in_array($currchar, $this->context->startingbkonchars))
219 foreach($this->highlightfile->blockcommenton as $bo)
221 if ($bo[0] != $currchar)
continue;
222 $boln = $this->context->bcolengths[$bo];
223 if (substr($line, $j, $boln)==$bo)
225 if ($boln > $currmax)
240 $out.= $this->context->prepro_parts[1];
243 $this->context->closingstrings = $this->context->bcomatches[$bkc];
244 $lineout = $this->
_munge($lineout);
245 $bkcout = str_replace(
">",
">", $bkc);
246 $bkcout = str_replace(
"<",
"<", $bkcout);
248 $out.= $this->context->blockcomment_parts[0].$bkcout;
250 $this->context->inbcomment = 1;
256 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && $this->context->inbcomment)
260 foreach($this->context->closingstrings as $bf)
262 if ($bf[0] != $currchar)
continue;
263 $bfln = $this->context->bcflengths[$bf];
264 if (substr($line, $j, $bfln)==$bf)
266 if ($bfln > $currmax)
278 $bkuout = str_replace(
">",
">", $bku);
279 $bkuout = str_replace(
"<",
"<", $bkuout);
280 $lineout .= $bkuout.$this->context->blockcomment_parts[1];
284 $this->context->inbcomment = 0;
289 if (isset($this->highlightfile->zones) && !$this->context->inbcomment && !$this->context->incomment && !$this->context->inquote)
293 foreach($this->starttags as $starttag)
295 if ($starttag[0] != $currchar)
continue;
296 $starttagln = $this->starttaglengths[$starttag];
298 if (substr($line, $j, $starttagln)==$starttag)
300 if ($starttagln > $startcurrmax)
302 $startcurrtag = $starttag;
303 $startcurrmax = $starttagln;
308 if ($startcurrmax != 0)
311 $tagout = str_replace(
">",
">", $startcurrtag);
312 $tagout = str_replace(
"<",
"<", $tagout);
313 $out.= ltrim($lineout);
314 array_push($this->langstack, $this->highlightfile);
315 array_push($this->contextstack, $this->context);
317 require_once $BEAUT_PATH.
"/HFile/".$this->startmap[$startcurrtag].
".php";
318 $this->endtaglist = $this->endtags[$startcurrtag];
319 if (isset($this->langcache[$startcurrtag]))
320 $this->highlightfile = $this->langcache[$startcurrtag];
323 $this->highlightfile =
new $this->startmap[$startcurrtag]();
324 $this->langcache[$startcurrtag] = $this->highlightfile;
326 $this->context =
new Context();
327 $this->context->from_language($this->highlightfile, $this->output_module);
329 $j += $startcurrmax-1;
334 foreach($this->endtaglist as $endtag)
337 if ($endtag[0] != $currchar)
continue;
338 $endtagln = strlen($endtag);
339 if (substr($line, $j, $endtagln)==$endtag)
341 if ($endtagln > $endcurrmax)
343 $endcurrtag = $endtag;
344 $endcurrmax = $endtagln;
351 $tagout = str_replace(
">",
">", $endcurrtag);
352 $tagout = str_replace(
"<",
"<", $tagout);
354 $lineout .=
"$tagout";
357 $this->highlightfile = array_pop($this->langstack);
358 $this->context = array_pop($this->contextstack);
359 $this->endtaglist =
array();
367 if ($this->context->incomment || $this->context->inbcomment)
369 if ($this->context->inbcomment)
371 if ($currchar ==
"<") $currchar =
"<";
372 else if ($currchar ==
">") $currchar =
">";
373 else if ($currchar ==
"&") $currchar =
"&";
376 $lineout .= $currchar;
377 if ($this->context->newline)
379 if (isset($this->statobj) && $this->statobj->harvest_comments) $this->statobj->comment_cache .=
" ";
380 $this->context->newline = 0;
382 if (isset($this->statobj) && $this->statobj->harvest_comments) $this->statobj->comment_cache .= $currchar;
387 $delim = ($j==0 || in_array($currchar, $this->context->alldelims) || ($j>0 && in_array($lineorig[$j-1], $this->context->alldelims)));
390 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->escaping &&
391 ((in_array($currchar, (
array)$this->highlightfile->stringchars) && $this->context->inquote && $currchar==$this->context->currquotechar) || (in_array($currchar, (
array)$this->highlightfile->stringchars) && !$this->context->inquote)))
396 if (!$this->context->escaping && isset($this->context->inquote) && !$this->context->inquote)
399 $lineout = $this->
_munge($lineout);
401 $this->context->inquote = 1;
402 if (isset($this->statobj) && $this->statobj->harvest_strings) $this->string_cache.=
" ";
403 if ($this->context->prepro)
405 $lineout = $this->context->prepro_parts[1].$currchar.$this->context->quote_parts[0];
409 $out.= $currchar.$this->context->quote_parts[0];
412 $this->context->currquotechar = $currchar;
415 else if ($this->context->inquote && !$this->context->escaping && $currchar == $this->context->currquotechar)
418 $this->context->inquote = 0;
419 if ($this->context->prepro)
421 $lineout .= $this->context->quote_parts[1].$this->context->prepro_parts[0].$lineorig[$j];
425 $lineout .= $this->context->quote_parts[1].$lineorig[$j];
429 $this->context->currquotechar =
"";
433 else if (!$this->context->inselection && $delim && !$this->context->inquote && ($stri=$this->_starts_with(substr($line, $j), $this->highlightfile->indent))!=
"")
436 if (!$this->context->inwhitespace)
439 $lineout .= str_repeat(
"\t", $this->context->ind);
442 $this->context->ind++;
443 $j += strlen($stri)-1;
447 else if (!$this->context->inselection && $delim && $this->context->ind>0 && !$this->context->inquote && ($stru=$this->_starts_with(substr($line, $j), $this->highlightfile->unindent))!=
"")
450 $this->context->ind--;
452 if (!$this->context->inwhitespace)
455 $lineout .= str_repeat(
"\t", $this->context->ind);
459 $j += strlen($stru)-1;
462 else if (!$this->context->inwhitespace || $currchar !=
" " || $currchar !=
"\t")
465 if ($this->context->inquote && isset($this->statobj) && $this->statobj->harvest_strings)
466 $this->statobj->string_cache .=$currchar;
467 $lineout .= htmlentities($currchar);
469 if ($this->context->inquote && $this->context->escaping)
472 $this->context->escaping = 0;
474 else if ($this->context->inquote && $currchar == $this->highlightfile->escchar && !$this->context->escaping)
477 $this->context->escaping = 1;
480 if ($currchar !=
" " && $currchar !=
"\t")
482 $this->context->inwhitespace = 0;
484 if (!$this->context->incomment && !$this->context->inbcomment && !$this->context->inquote)
486 $lineout = $this->
_munge($lineout);
490 if ($this->context->prepro)
492 $lineout .= $this->context->prepro_parts[1];
496 if ($this->context->incomment)
498 $out.= $this->context->linecomment_parts[1];
500 if ($i<($aln-1)) $lineout .=
"\n";
501 if ($this->context->lineselect) $lineout.= $this->context->select_parts[1];
503 $this->context->newline = 1;
504 $this->context->lineselect = 0;
508 if ($this->context->incomment)
510 $out.= $this->context->linecomment_parts[1];
512 else if ($this->context->inbcomment)
514 $out.= $this->context->blockcomment_parts[1];
516 else if ($this->context->inselection)
518 $out.= $this->context->select_parts[1];
520 if (isset($this->context->code_parts[1]))
$out.= $this->context->code_parts[1];
522 $pad = str_repeat(
" ", $this->highlightfile->indent_depth);
523 $out = str_replace (
"\t",$pad,
$out);
for( $i=1;$i< 200;$i++)
Holds the type of the event to listen for.
_starts_with($text, $array)
Create styles array
The data for the language used.