[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TMarkdown class file 4 * 5 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TMarkdown.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * Using TTextHighlighter and MarkdownParser classes 15 */ 16 Prado::using('System.Web.UI.WebControls.TTextHighlighter'); 17 Prado::using('System.3rdParty.Markdown.MarkdownParser'); 18 19 /** 20 * TMarkdown class 21 * 22 * TMarkdown is a control that produces HTML from code with markdown syntax. 23 * 24 * Markdown is a text-to-HTML conversion tool for web writers. Markdown allows 25 * you to write using an easy-to-read, easy-to-write plain text format, then 26 * convert it to structurally valid XHTML (or HTML). 27 * Further documentation regarding Markdown can be found at 28 * http://daringfireball.net/projects/markdown/ 29 * 30 * To use TMarkdown, simply enclose the content to be rendered within 31 * the body of TMarkdown in a template. 32 * 33 * See http://www.pradosoft.com/demos/quickstart/?page=Markdown for 34 * details on the Markdown syntax usage. 35 * 36 * TMarkdown also performs syntax highlighting for code blocks whose language 37 * is recognized by {@link TTextHighlighter}. 38 * The language of a code block must be specified in the first line of the block 39 * and enclosed within a pair of square brackets (e.g. [php]). 40 * 41 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 42 * @version $Id: TMarkdown.php 1397 2006-09-07 07:55:53Z wei $ 43 * @package System.Web.UI.WebControls 44 * @since 3.0.1 45 */ 46 class TMarkdown extends TTextHighlighter 47 { 48 /** 49 * Processes a text string. 50 * This method is required by the parent class. 51 * @param string text string to be processed 52 * @return string the processed text result 53 */ 54 public function processText($text) 55 { 56 $renderer = new MarkdownParser; 57 $result = $renderer->parse($text); 58 return preg_replace_callback( 59 '/<pre><code>\[\s*(\w+)\s*\]\n+((.|\n)*?)\s*<\\/code><\\/pre>/im', 60 array($this, 'highlightCode'), $result); 61 } 62 63 /** 64 * Highlights source code using TTextHighlighter 65 * @param array matches of code blocks 66 * @return string highlighted code. 67 */ 68 protected function highlightCode($matches) 69 { 70 $geshi=new GeSHi(html_entity_decode($matches[2],ENT_QUOTES,'UTF-8'), $matches[1]); 71 if($this->getShowLineNumbers()) 72 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); 73 $geshi->enable_classes(); 74 if($this->getEnableCopyCode()) 75 $geshi->set_header_content($this->getHeaderTemplate()); 76 77 return $geshi->parse_code(); 78 } 79 } 80 81 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |