cvs: pear /Text_Wiki/Text/Wiki/Parse/Default Code.php

From: Date: Tue, 21 Feb 2006 08:29:49 +0000
Subject: cvs: pear /Text_Wiki/Text/Wiki/Parse/Default Code.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-38436@lists.php.net to get a copy of this message
delatbabel Tue Feb 21 08:29:49 2006 UTC Modified files: /pear/Text_Wiki/Text/Wiki/Parse/Default Code.php Log: Change to allow code type="parsed" http://cvs.php.net/viewcvs.cgi/pear/Text_Wiki/Text/Wiki/Parse/Default/Code.php?r1=1.8&r2=1.9&diff_format=u Index: pear/Text_Wiki/Text/Wiki/Parse/Default/Code.php diff -u pear/Text_Wiki/Text/Wiki/Parse/Default/Code.php:1.8 pear/Text_Wiki/Text/Wiki/Parse/Default/Code.php:1.9 --- pear/Text_Wiki/Text/Wiki/Parse/Default/Code.php:1.8 Tue Feb 21 08:10:59 2006 +++ pear/Text_Wiki/Text/Wiki/Parse/Default/Code.php Tue Feb 21 08:29:49 2006 @@ -12,7 +12,7 @@ * * @license LGPL * -* @version $Id: Code.php,v 1.8 2006/02/21 08:10:59 delatbabel Exp $ +* @version $Id: Code.php,v 1.9 2006/02/21 08:29:49 delatbabel Exp $ * */ @@ -85,11 +85,79 @@ $attr['type'] = ''; } - // retain the options - $options = array( - 'text' => $matches[2], - 'attr' => $attr - ); + // + // Check to see if the preformatted area has the type of "parsed", + // in which case we want to parse it not just present it as a plain + // block of text. This means we can have wiki links, etc, within + // a plain text block. + // + if ($attr['type'] == "parsed") { + // + // Yes, parse this block. Find the start and end of the block. + // + if ($args == '') { + $start = $this->wiki->addToken( + $this->rule, + array('type' => 'start') + ); + + } else { + // get the attributes... + $attr = $this->getAttrs($args); + // ... and make sure we have a 'type' + if (! isset($attr['type'])) { + $attr['type'] = ''; + } + $start = $this->wiki->addToken( + $this->rule, + array('type' => 'start', + 'attr' => $attr + ) + ); + } + + $end = $this->wiki->addToken( + $this->rule, + array('type' => 'end', + 'attr' => $attr) + ); + + // + // Tokenize the body of the block. + // + $text = str_replace("\t", " ", $matches[3]); + $body = explode("\n", $text); + $newtext = ""; + $lines = count($body); + + // + // Add a new line to the token array. + // + $newline = $this->wiki->addToken( + 'Raw', + array( 'text' => "\n" ) + ); + + for ($line = 0; $line < $lines; $line++) { + $newtext .= $body[$line]; + if ($line < $lines-1) { + // + // Don't want a newline after the last line. + // + $newtext .= $newline; + } + } + + return "\n" . $start . $newtext . $end . "\n"; + + } else { + + // retain the options + $options = array( + 'text' => $matches[2], + 'attr' => $attr + ); + } } return $this->wiki->addToken($this->rule, $options) . $matches[3];

« previous php.pear.cvs (#38436) next »