Skip to content

Commit

Permalink
Change to allow code type="parsed"
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.php.net/repository/pear/packages/Text_Wiki/trunk@207654 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Del Elson committed Feb 21, 2006
1 parent 8f17da4 commit 11f5be5
Showing 1 changed file with 73 additions and 5 deletions.
78 changes: 73 additions & 5 deletions Text/Wiki/Parse/Default/Code.php
Expand Up @@ -85,11 +85,79 @@ function process(&$matches)
$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];
Expand Down

0 comments on commit 11f5be5

Please sign in to comment.