59 if (isset($contextstack) && is_array($contextstack)) {
60 $this->contextstack = $contextstack;
61 $this->context = array_pop($contextstack);
62 $this->context->inwhitespace = 0;
65 $this->context->from_language($this->highlightfile, $this->output_module);
66 $this->contextstack =
array();
68 array_push($this->contextstack, $this->context);
69 $this->langstack =
array();
71 if (isset($this->highlightfile->zones)) {
74 $this->starttags =
array();
75 $this->endtags =
array();
76 $this->starttaglengths =
array();
77 foreach ($this->highlightfile->zones as $zone) {
78 $this->startmap[$zone[0]] = $zone[2];
79 array_push($this->starttags, $zone[0]);
80 if (!isset($this->endtags[$zone[0]])) {
81 $this->endtags[$zone[0]] =
array();
83 array_push($this->endtags[$zone[0]], $zone[1]);
84 $this->starttaglengths[$zone[0]] = strlen($zone[0]);
86 $this->endtaglist =
array();
87 $this->langcache =
array();
92 $arr = preg_split(
"/\n/",
$text);
95 if (isset($this->context->code_parts[0])) {
96 $out.= $this->context->code_parts[0];
98 for (
$i=0;
$i<$aln;
$i++) {
99 $this->context->prepro = 0;
101 if ($this->context->preprolength>0 && substr($line, 0, $this->context->preprolength)==$this->highlightfile->prepro) {
102 $out.= $this->context->prepro_parts[0];
103 $this->context->prepro = 1;
107 $this->context->inwhitespace = 1;
110 $this->context->incomment = 0;
112 if (isset($this->highlightfile->lineselect) && !$this->context->inselection && substr($line, 0, strlen($this->highlightfile->lineselect))==$this->highlightfile->lineselect) {
113 $out.= $this->context->select_parts[0];
114 $line = substr($line, strlen($this->highlightfile->lineselect));
115 $this->context->lineselect = 1;
119 if ($this->highlightfile->notrim==0) {
126 $sw = $this->
_starts_with($lineorig, $this->highlightfile->unindent);
127 if ($lineorig !=
"") {
128 if ($this->context->ind>0 && $sw!=
"") {
130 $lineout = str_repeat(
"\t", ($this->context->ind-1));
132 $lineout = str_repeat(
"\t", $this->context->ind);
135 $ln = strlen($lineorig);
136 for ($j=0; $j<$ln; $j++) {
137 $currchar = $lineorig[$j];
140 if (isset($this->highlightfile->selecton) && !$this->context->inselection &&
141 !$this->context->inquote && !$this->context->inbcomment &&
142 substr($line, $j, strlen($this->highlightfile->selecton))==$this->highlightfile->selecton) {
144 $lineout = $this->
_munge($lineout) . $this->context->select_parts[0];
147 $this->context->inselection = 1;
148 $j+= strlen($this->highlightfile->selecton)-1;
152 if (isset($this->highlightfile->selectoff) && $this->context->inselection &&
153 substr($line, $j, strlen($this->highlightfile->selectoff))==$this->highlightfile->selectoff) {
155 $lineout.=$this->context->select_parts[1];
158 $this->context->inselection = 0;
159 $j+= strlen($this->highlightfile->selectoff);
164 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->incomment && !($this->highlightfile->perl && $j>0 && $line[$j-1]==
"$")) {
167 foreach ($this->highlightfile->linecommenton as
$l) {
168 if ($l[0] != $currchar) {
171 $lln = $this->context->lcolengths[
$l];
172 if (substr($line, $j, $lln)==$l) {
173 if ($lln > $currmax) {
183 $line = substr($line, $j);
184 $lineout = $this->
_munge($lineout);
185 $line = htmlentities($line);
187 if ($this->context->prepro) {
188 $out.= $this->context->prepro_parts[1];
189 $this->context->prepro = 0;
191 $out.= $this->context->linecomment_parts[0] . $line;
192 if (isset($this->statobj) && $this->statobj->harvest_comments) {
193 $this->statobj->comment_cache .=
" " . substr($line, $lncl);
196 $this->context->incomment = 1;
204 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->inbcomment && in_array($currchar, $this->context->startingbkonchars)) {
207 foreach ($this->highlightfile->blockcommenton as $bo) {
208 if ($bo[0] != $currchar) {
211 $boln = $this->context->bcolengths[$bo];
212 if (substr($line, $j, $boln)==$bo) {
213 if ($boln > $currmax) {
225 $out.= $this->context->prepro_parts[1];
228 $this->context->closingstrings = $this->context->bcomatches[$bkc];
229 $lineout = $this->
_munge($lineout);
230 $bkcout = str_replace(
">",
">", $bkc);
231 $bkcout = str_replace(
"<",
"<", $bkcout);
233 $out.= $this->context->blockcomment_parts[0] . $bkcout;
235 $this->context->inbcomment = 1;
241 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && $this->context->inbcomment) {
244 foreach ($this->context->closingstrings as $bf) {
245 if ($bf[0] != $currchar) {
248 $bfln = $this->context->bcflengths[$bf];
249 if (substr($line, $j, $bfln)==$bf) {
250 if ($bfln > $currmax) {
260 $bkuout = str_replace(
">",
">", $bku);
261 $bkuout = str_replace(
"<",
"<", $bkuout);
262 $lineout .= $bkuout . $this->context->blockcomment_parts[1];
266 $this->context->inbcomment = 0;
271 if (isset($this->highlightfile->zones) && !$this->context->inbcomment && !$this->context->incomment && !$this->context->inquote) {
274 foreach ($this->starttags as $starttag) {
275 if ($starttag[0] != $currchar) {
278 $starttagln = $this->starttaglengths[$starttag];
280 if (substr($line, $j, $starttagln)==$starttag) {
281 if ($starttagln > $startcurrmax) {
282 $startcurrtag = $starttag;
283 $startcurrmax = $starttagln;
287 if ($startcurrmax != 0) {
289 $tagout = str_replace(
">",
">", $startcurrtag);
290 $tagout = str_replace(
"<",
"<", $tagout);
291 $out.= ltrim($lineout);
292 array_push($this->langstack, $this->highlightfile);
293 array_push($this->contextstack, $this->context);
295 require_once $BEAUT_PATH .
"/HFile/" . $this->startmap[$startcurrtag] .
".php";
296 $this->endtaglist = $this->endtags[$startcurrtag];
297 if (isset($this->langcache[$startcurrtag])) {
298 $this->highlightfile = $this->langcache[$startcurrtag];
300 $this->highlightfile =
new $this->startmap[$startcurrtag]();
301 $this->langcache[$startcurrtag] = $this->highlightfile;
303 $this->context =
new Context();
304 $this->context->from_language($this->highlightfile, $this->output_module);
306 $j += $startcurrmax-1;
311 foreach ($this->endtaglist as $endtag) {
312 if ($endtag[0] != $currchar) {
315 $endtagln = strlen($endtag);
316 if (substr($line, $j, $endtagln)==$endtag) {
317 if ($endtagln > $endcurrmax) {
318 $endcurrtag = $endtag;
319 $endcurrmax = $endtagln;
323 if ($endcurrmax!=0) {
325 $tagout = str_replace(
">",
">", $endcurrtag);
326 $tagout = str_replace(
"<",
"<", $tagout);
328 $lineout .=
"$tagout";
331 $this->highlightfile = array_pop($this->langstack);
332 $this->context = array_pop($this->contextstack);
333 $this->endtaglist =
array();
340 if ($this->context->incomment || $this->context->inbcomment) {
341 if ($this->context->inbcomment) {
342 if ($currchar ==
"<") {
344 } elseif ($currchar ==
">") {
346 } elseif ($currchar ==
"&") {
351 $lineout .= $currchar;
352 if ($this->context->newline) {
353 if (isset($this->statobj) && $this->statobj->harvest_comments) {
354 $this->statobj->comment_cache .=
" ";
356 $this->context->newline = 0;
358 if (isset($this->statobj) && $this->statobj->harvest_comments) {
359 $this->statobj->comment_cache .= $currchar;
365 $delim = ($j==0 || in_array($currchar, $this->context->alldelims) || ($j>0 && in_array($lineorig[$j-1], $this->context->alldelims)));
368 if (!$this->context->lineselect && !$this->context->inselection && !$this->context->escaping &&
369 ((in_array($currchar, (
array) $this->highlightfile->stringchars) && $this->context->inquote && $currchar==$this->context->currquotechar) || (in_array($currchar, (
array) $this->highlightfile->stringchars) && !$this->context->inquote))) {
373 if (!$this->context->escaping && isset($this->context->inquote) && !$this->context->inquote) {
375 $lineout = $this->
_munge($lineout);
377 $this->context->inquote = 1;
378 if (isset($this->statobj) && $this->statobj->harvest_strings) {
379 $this->string_cache.=
" ";
381 if ($this->context->prepro) {
382 $lineout = $this->context->prepro_parts[1] . $currchar . $this->context->quote_parts[0];
384 $out.= $currchar . $this->context->quote_parts[0];
387 $this->context->currquotechar = $currchar;
390 elseif ($this->context->inquote && !$this->context->escaping && $currchar == $this->context->currquotechar) {
392 $this->context->inquote = 0;
393 if ($this->context->prepro) {
394 $lineout .= $this->context->quote_parts[1] . $this->context->prepro_parts[0] . $lineorig[$j];
396 $lineout .= $this->context->quote_parts[1] . $lineorig[$j];
400 $this->context->currquotechar =
"";
404 elseif (!$this->context->inselection && $delim && !$this->context->inquote && ($stri=$this->_starts_with(substr($line, $j), $this->highlightfile->indent))!=
"") {
406 if (!$this->context->inwhitespace) {
408 $lineout .= str_repeat(
"\t", $this->context->ind);
411 $this->context->ind++;
412 $j += strlen($stri)-1;
415 elseif (!$this->context->inselection && $delim && $this->context->ind>0 && !$this->context->inquote && ($stru=$this->_starts_with(substr($line, $j), $this->highlightfile->unindent))!=
"") {
417 $this->context->ind--;
419 if (!$this->context->inwhitespace) {
421 $lineout .= str_repeat(
"\t", $this->context->ind);
425 $j += strlen($stru)-1;
428 elseif (!$this->context->inwhitespace || $currchar !=
" " || $currchar !=
"\t") {
430 if ($this->context->inquote && isset($this->statobj) && $this->statobj->harvest_strings) {
431 $this->statobj->string_cache .=$currchar;
433 $lineout .= htmlentities($currchar);
435 if ($this->context->inquote && $this->context->escaping) {
437 $this->context->escaping = 0;
438 } elseif ($this->context->inquote && $currchar == $this->highlightfile->escchar && !$this->context->escaping) {
440 $this->context->escaping = 1;
443 if ($currchar !=
" " && $currchar !=
"\t") {
444 $this->context->inwhitespace = 0;
446 if (!$this->context->incomment && !$this->context->inbcomment && !$this->context->inquote) {
447 $lineout = $this->
_munge($lineout);
450 if ($this->context->prepro) {
451 $lineout .= $this->context->prepro_parts[1];
455 if ($this->context->incomment) {
456 $out.= $this->context->linecomment_parts[1];
461 if ($this->context->lineselect) {
462 $lineout.= $this->context->select_parts[1];
465 $this->context->newline = 1;
466 $this->context->lineselect = 0;
469 if ($this->context->incomment) {
470 $out.= $this->context->linecomment_parts[1];
471 } elseif ($this->context->inbcomment) {
472 $out.= $this->context->blockcomment_parts[1];
473 } elseif ($this->context->inselection) {
474 $out.= $this->context->select_parts[1];
476 if (isset($this->context->code_parts[1])) {
477 $out.= $this->context->code_parts[1];
480 $pad = str_repeat(
" ", $this->highlightfile->indent_depth);
481 $out = str_replace(
"\t", $pad,
$out);
_starts_with($text, $array)
Create styles array
The data for the language used.