コード例 #1
0
 /**
  * Formatting the TypoScript code in $this->raw based on the data collected by $this->regHighLight in $this->highLightData
  *
  * @param mixed $lineNumDat If blank, linenumbers are NOT printed. If array then the first key is the linenumber offset to add to the internal counter.
  * @param bool $highlightBlockMode If set, then the highlighted output will be formatted in blocks based on the brace levels. prespace will be ignored and empty lines represented with a single no-break-space.
  * @return string HTML content
  * @access private
  * @see doSyntaxHighlight()
  */
 public function syntaxHighlight_print($lineNumDat, $highlightBlockMode)
 {
     // Registers all error messages in relation to their linenumber
     $errA = array();
     foreach ($this->errors as $err) {
         $errA[$err[2]][] = $err[0];
     }
     // Generates the syntax highlighted output:
     $lines = array();
     foreach ($this->raw as $rawP => $value) {
         $start = 0;
         $strlen = strlen($value);
         $lineC = '';
         if (is_array($this->highLightData[$rawP])) {
             foreach ($this->highLightData[$rawP] as $set) {
                 $len = $strlen - $start - $set[1];
                 if ($len > 0) {
                     $part = substr($value, $start, $len);
                     $start += $len;
                     $st = $this->highLightStyles[isset($this->highLightStyles[$set[0]]) ? $set[0] : 'default'];
                     if (!$highlightBlockMode || $set[0] !== 'prespace') {
                         $lineC .= $st[0] . htmlspecialchars($part) . $st[1];
                     }
                 } elseif ($len < 0) {
                     debug(array($len, $value, $rawP));
                 }
             }
         } else {
             debug(array($value));
         }
         if (strlen($value) > $start) {
             $lineC .= $this->highLightStyles['ignored'][0] . htmlspecialchars(substr($value, $start)) . $this->highLightStyles['ignored'][1];
         }
         if ($errA[$rawP]) {
             $lineC .= $this->highLightStyles['error'][0] . '<strong> - ERROR:</strong> ' . htmlspecialchars(implode(';', $errA[$rawP])) . $this->highLightStyles['error'][1];
         }
         if ($highlightBlockMode && $this->highLightData_bracelevel[$rawP]) {
             $lineC = str_pad('', $this->highLightData_bracelevel[$rawP] * 2, ' ', STR_PAD_LEFT) . '<span style="' . $this->highLightBlockStyles . ($this->highLightBlockStyles_basecolor ? 'background-color: ' . $this->modifyHTMLColorAll($this->highLightBlockStyles_basecolor, -$this->highLightData_bracelevel[$rawP] * 16) : '') . '">' . ($lineC !== '' ? $lineC : '&nbsp;') . '</span>';
         }
         if (is_array($lineNumDat)) {
             $lineNum = $rawP + $lineNumDat[0];
             if ($this->parentObject instanceof ExtendedTemplateService) {
                 $lineNum = $this->parentObject->ext_lnBreakPointWrap($lineNum, $lineNum);
             }
             $lineC = $this->highLightStyles['linenum'][0] . str_pad($lineNum, 4, ' ', STR_PAD_LEFT) . ':' . $this->highLightStyles['linenum'][1] . ' ' . $lineC;
         }
         $lines[] = $lineC;
     }
     return '<pre class="ts-hl">' . implode(LF, $lines) . '</pre>';
 }