예제 #1
0
파일: xhtml.php 프로젝트: sawachan/dokuwiki
 /**
  * Use GeSHi to highlight language syntax in code and file blocks
  *
  * @author Andreas Gohr <*****@*****.**>
  * @param string $type     code|file
  * @param string $text     text to show
  * @param string $language programming language to use for syntax highlighting
  * @param string $filename file path label
  */
 function _highlight($type, $text, $language = null, $filename = null)
 {
     global $ID;
     global $lang;
     if ($filename) {
         // add icon
         list($ext) = mimetype($filename, false);
         $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
         $class = 'mediafile mf_' . $class;
         $this->doc .= '<dl class="' . $type . '">' . DOKU_LF;
         $this->doc .= '<dt><a href="' . exportlink($ID, 'code', array('codeblock' => $this->_codeblock)) . '" title="' . $lang['download'] . '" class="' . $class . '">';
         $this->doc .= hsc($filename);
         $this->doc .= '</a></dt>' . DOKU_LF . '<dd>';
     }
     if ($text[0] == "\n") {
         $text = substr($text, 1);
     }
     if (substr($text, -1) == "\n") {
         $text = substr($text, 0, -1);
     }
     if (is_null($language)) {
         $this->doc .= '<pre class="' . $type . '">' . $this->_xmlEntities($text) . '</pre>' . DOKU_LF;
     } else {
         $class = 'code';
         //we always need the code class to make the syntax highlighting apply
         if ($type != 'code') {
             $class .= ' ' . $type;
         }
         $this->doc .= "<pre class=\"{$class} {$language}\">" . p_xhtml_cached_geshi($text, $language, '') . '</pre>' . DOKU_LF;
     }
     if ($filename) {
         $this->doc .= '</dd></dl>' . DOKU_LF;
     }
     $this->_codeblock++;
 }
예제 #2
0
 /**
  * Insert HTML if allowed
  *
  * @param  string $text      html text
  * @param  string $wrapper   html element to wrap result if $conf['htmlok'] is okff
  *
  * @author Andreas Gohr <*****@*****.**>
  */
 function html($text, $wrapper = 'code')
 {
     $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
 }
 function _highlight($type, $text, $language = null, $filename = null)
 {
     global $conf;
     global $ID;
     global $lang;
     if ($filename) {
         list($ext) = mimetype($filename, false);
         $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext);
         $class = 'mediafile mf_' . $class;
         $this->doc .= '<dl class="' . $type . '">' . DOKU_LF;
         $this->doc .= '<dt><a href="' . exportlink($ID, 'code', array('codeblock' => $this->_codeblock)) . '" title="' . $lang['download'] . '" class="' . $class . '">';
         $this->doc .= hsc($filename);
         $this->doc .= '</a></dt>' . DOKU_LF . '<dd>';
     }
     if ($text[0] == "\n") {
         $text = substr($text, 1);
     }
     if (substr($text, -1) == "\n") {
         $text = substr($text, 0, -1);
     }
     if (is_null($language)) {
         $this->preformatted($text, $type);
     } else {
         $class = 'code';
         if ($type != 'code') {
             $class .= ' ' . $type;
         }
         $this->doc .= "<pre class=\"{$class} {$language}\" " . $this->_getID(1, 1) . ">" . p_xhtml_cached_geshi($text, $language, '') . $this->_getLink() . '</pre>' . DOKU_LF;
     }
     if ($filename) {
         $this->doc .= '</dd></dl>' . DOKU_LF;
     }
     $this->_codeblock++;
 }
예제 #4
0
 /**
  * Callback for code text
  *
  * Uses GeSHi to highlight language syntax
  *
  * @author Andreas Gohr <*****@*****.**>
  */
 function code($text, $language = NULL)
 {
     global $conf;
     if (is_null($language)) {
         $this->preformatted($text);
     } else {
         //strip leading and trailing blank line
         $text = preg_replace('/^\\s*?\\n/', '', $text);
         $text = preg_replace('/\\s*?\\n$/', '', $text);
         $this->doc .= p_xhtml_cached_geshi($text, $language);
     }
 }
예제 #5
0
 /**
  * @param string $type
  * @param string $text
  * @param string $language
  */
 function _highlight($type, $text, $language = null)
 {
     $style_name = $this->docHandler->getStyleName('source code');
     if ($type == "file") {
         $style_name = $this->docHandler->getStyleName('source file');
     }
     if (is_null($language)) {
         $this->_preformatted($text, $style_name);
         return;
     }
     // Use cahched geshi
     $highlighted_code = p_xhtml_cached_geshi($text, $language, '');
     // remove useless leading and trailing whitespace-newlines
     $highlighted_code = preg_replace('/^&nbsp;\\n/', '', $highlighted_code);
     $highlighted_code = preg_replace('/\\n&nbsp;$/', '', $highlighted_code);
     // replace styles
     $highlighted_code = str_replace("</span>", "</text:span>", $highlighted_code);
     $highlighted_code = preg_replace_callback('/<span class="([^"]+)">/', array($this, '_convert_css_styles'), $highlighted_code);
     // cleanup leftover span tags
     $highlighted_code = preg_replace('/<span[^>]*>/', "<text:span>", $highlighted_code);
     $highlighted_code = str_replace("&nbsp;", "&#xA0;", $highlighted_code);
     // Replace links with ODT link syntax
     $highlighted_code = preg_replace_callback('/<a (href="[^"]*">.*)<\\/a>/', array($this, '_convert_geshi_links'), $highlighted_code);
     $this->_preformatted($highlighted_code, $style_name, false);
 }
예제 #6
0
 /**
  * Callback for code text
  *
  * Uses GeSHi to highlight language syntax
  *
  * @author Andreas Gohr <*****@*****.**>
  */
 public function code($text, $language = NULL)
 {
     global $conf;
     if (is_null($language)) {
         $this->preformatted($text);
     } else {
         $this->doc .= p_xhtml_cached_geshi($text, $language);
     }
 }