Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Code.php

Documentation is available at Code.php

  1. <?php
  2.  
  3. class Text_Wiki_Render_Xhtml_Code extends Text_Wiki_Render {
  4.     
  5.     
  6.     /**
  7.     * 
  8.     * Renders a token into text matching the requested format.
  9.     * 
  10.     * @access public
  11.     * 
  12.     * @param array $options The "options" portion of the token (second
  13.     *  element).
  14.     * 
  15.     * @return string The text rendered from the token options.
  16.     * 
  17.     */
  18.     
  19.     function token($options)
  20.     {
  21.         $text $options['text'];
  22.         $attr $options['attr'];
  23.         
  24.         if (strtolower($attr['type']== 'php'{
  25.             
  26.             // PHP code example
  27.             
  28.             // add the PHP tags
  29.             $text "<?php\n" $options['text'"\n?>"// <?php
  30.             
  31.             // convert tabs to four spaces
  32.             $text str_replace("\t""    "$text);
  33.             
  34.             // colorize the code block (also converts HTML entities and adds
  35.             // <code>...</code> tags)
  36.             ob_start();
  37.             highlight_string($text);
  38.             $text ob_get_contents();
  39.             ob_end_clean();
  40.             
  41.             // replace <br /> tags with simple newlines
  42.             //$text = str_replace("<br />", "\n", $text);
  43.             
  44.             // replace non-breaking space with simple spaces
  45.             //$text = str_replace("&nbsp;", " ", $text);
  46.             
  47.             // replace <br /> tags with simple newlines
  48.             // replace non-breaking space with simple spaces
  49.             // translate old HTML to new XHTML
  50.             // courtesy of research by A. Kalin :-)
  51.             $map = array(
  52.                 '<br />'  => "\n",
  53.                 '&nbsp;'  => ' ',
  54.                 '<font'   => '<span',
  55.                 '</font>' => '</span>',
  56.                 'color="' => 'style="color:'
  57.             );
  58.             $text strtr($text$map);
  59.            
  60.             // get rid of the last newline inside the code block
  61.             // (becuase higlight_string puts one there)
  62.             if (substr($text-8== "\n</code>"{
  63.                 $text substr($text0-8"</code>";
  64.             }
  65.             
  66.             // done
  67.             $text = "<pre>$text</pre>";
  68.         
  69.         elseif (strtolower($attr['type']== 'html'{
  70.         
  71.             // HTML code example:
  72.             // add <html> opening and closing tags,
  73.             // convert tabs to four spaces,
  74.             // convert entities.
  75.             $text str_replace("\t""    "$text);
  76.             $text = "<html>\n$text\n</html>";
  77.             $text htmlentities($text);
  78.             $text = "<pre><code>$text</code></pre>";
  79.             
  80.         else {
  81.             // generic code example:
  82.             // convert tabs to four spaces,
  83.             // convert entities.
  84.             $text str_replace("\t""    "$text);
  85.             $text htmlentities($text);
  86.             $text = "<pre><code>$text</code></pre>";
  87.         }
  88.         
  89.         return "\n$text\n\n";
  90.     }
  91. }
  92. ?>

Documentation generated on Mon, 11 Mar 2019 13:51:28 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.