Skip to content

Commit

Permalink
somehow, an earlier version of Text_Wiki was added to PEAR CVS; this …
Browse files Browse the repository at this point in the history
…commit reflects the 0.14 version, which should have been imported in the first place.

git-svn-id: https://svn.php.net/repository/pear/packages/Text_Wiki/trunk@157782 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Paul M Jones committed May 2, 2004
1 parent 66233b6 commit 72faf53
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 52 deletions.
59 changes: 38 additions & 21 deletions Text/Wiki.php
Expand Up @@ -28,7 +28,7 @@
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @version 0.11 alpha
* @version 0.14 alpha
*
*/

Expand Down Expand Up @@ -98,13 +98,6 @@ class Text_Wiki {
)
),

'newline' => array(
'file' => 'Text/Wiki/Rule/newline.php',
'name' => 'Text_Wiki_Rule_newline',
'flag' => true,
'conf' => array()
),

'heading' => array(
'file' => 'Text/Wiki/Rule/heading.php',
'name' => 'Text_Wiki_Rule_heading',
Expand All @@ -119,13 +112,27 @@ class Text_Wiki {
'conf' => array()
),

'break' => array(
'file' => 'Text/Wiki/Rule/break.php',
'name' => 'Text_Wiki_Rule_break',
'flag' => true,
'conf' => array()
),

'blockquote' => array(
'file' => 'Text/Wiki/Rule/blockquote.php',
'name' => 'Text_Wiki_Rule_blockquote',
'flag' => true,
'conf' => array()
),

'list' => array(
'file' => 'Text/Wiki/Rule/list.php',
'name' => 'Text_Wiki_Rule_list',
'flag' => true,
'conf' => array()
),

'deflist' => array(
'file' => 'Text/Wiki/Rule/deflist.php',
'name' => 'Text_Wiki_Rule_deflist',
Expand All @@ -144,13 +151,6 @@ class Text_Wiki {
)
),

'list' => array(
'file' => 'Text/Wiki/Rule/list.php',
'name' => 'Text_Wiki_Rule_list',
'flag' => true,
'conf' => array()
),

'embed' => array(
'file' => 'Text/Wiki/Rule/embed.php',
'name' => 'Text_Wiki_Rule_embed',
Expand Down Expand Up @@ -183,6 +183,22 @@ class Text_Wiki {
'conf' => array()
),

'newline' => array(
'file' => 'Text/Wiki/Rule/newline.php',
'name' => 'Text_Wiki_Rule_newline',
'flag' => true,
'conf' => array(
'skip' => array(
'heading',
'horiz',
'deflist',
'table',
'list',
'toc'
)
)
),

'center' => array(
'file' => 'Text/Wiki/Rule/center.php',
'name' => 'Text_Wiki_Rule_center',
Expand All @@ -196,6 +212,7 @@ class Text_Wiki {
'flag' => true,
'conf' => array(
'skip' => array(
'blockquote',
'heading',
'horiz',
'deflist',
Expand Down Expand Up @@ -294,16 +311,16 @@ class Text_Wiki {
'conf' => array()
),

'entities' => array(
'file' => 'Text/Wiki/Rule/entities.php',
'name' => 'Text_Wiki_Rule_entities',
'tighten' => array(
'file' => 'Text/Wiki/Rule/tighten.php',
'name' => 'Text_Wiki_Rule_tighten',
'flag' => true,
'conf' => array()
),

'tighten' => array(
'file' => 'Text/Wiki/Rule/tighten.php',
'name' => 'Text_Wiki_Rule_tighten',
'entities' => array(
'file' => 'Text/Wiki/Rule/entities.php',
'name' => 'Text_Wiki_Rule_entities',
'flag' => true,
'conf' => array()
)
Expand Down
12 changes: 9 additions & 3 deletions Text/Wiki/Rule/blockquote.php
Expand Up @@ -115,6 +115,8 @@ function process(&$matches)
// dummy value (boolean true)...
array_push($stack, true);

$return .= "\n";

// ...and add a start token to the return.
$return .= $this->addToken(
array(
Expand All @@ -123,7 +125,7 @@ function process(&$matches)
)
);

$return .= "\n";
$return .= "\n\n";
}

// remove a level?
Expand All @@ -135,6 +137,8 @@ function process(&$matches)
// and the indent level are the same.
array_pop($stack);

$return .= "\n\n";

$return .= $this->addToken(
array (
'type' => 'end',
Expand All @@ -146,11 +150,13 @@ function process(&$matches)
}

// add the line text.
$return .= $text . "\n";
$return .= $text;
}

// the last line may have been indented. go through the stack
// and create end-tokens until the stack is empty.
$return .= "\n";

while (count($stack) > 0) {
array_pop($stack);
$return .= $this->addToken(
Expand All @@ -162,7 +168,7 @@ function process(&$matches)
}

// we're done! send back the replacement text.
return "\n$return";
return "$return\n";
}


Expand Down
90 changes: 90 additions & 0 deletions Text/Wiki/Rule/break.php
@@ -0,0 +1,90 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pmjones@ciaweb.net> |
// +----------------------------------------------------------------------+
//
// $Id$


/**
*
* This class implements a Text_Wiki_Rule to mark forced line breaks in the
* source text.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/

class Text_Wiki_Rule_break extends Text_Wiki_Rule {


/**
*
* The regular expression used to parse the source text and find
* matches conforming to this rule. Used by the parse() method.
*
* @access public
*
* @var string
*
* @see parse()
*
*/

var $regex = '/ _\n/';


/**
*
* Generates a replacement token for the matched text.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A delimited token to be used as a placeholder in
* the source text.
*
*/

function process(&$matches)
{
return $this->addToken();
}


/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/

function renderXhtml($options)
{
return "<br />\n";
}
}

?>
2 changes: 1 addition & 1 deletion Text/Wiki/Rule/deflist.php
Expand Up @@ -115,7 +115,7 @@ function process(&$matches)
$return .= $this->addToken($options);

// done!
return $return;
return "\n" . $return . "\n";
}


Expand Down
2 changes: 1 addition & 1 deletion Text/Wiki/Rule/heading.php
Expand Up @@ -85,7 +85,7 @@ function process(&$matches)
)
);

return $start . $matches[2] . $end;
return $start . $matches[2] . $end . "\n";
}


Expand Down
2 changes: 1 addition & 1 deletion Text/Wiki/Rule/list.php
Expand Up @@ -223,7 +223,7 @@ function process(&$matches)
}

// we're done! send back the replacement text.
return "\n" . $return;
return "\n" . $return . "\n";
}


Expand Down
9 changes: 5 additions & 4 deletions Text/Wiki/Rule/newline.php
Expand Up @@ -21,8 +21,9 @@

/**
*
* This class implements a Text_Wiki_Rule to mark "hard" newlines in the
* source text.
* This class implements a Text_Wiki_Rule to mark implied line breaks in the
* source text, usually a single carriage return in the middle of a paragraph
* or block-quoted text.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
Expand All @@ -46,7 +47,7 @@ class Text_Wiki_Rule_newline extends Text_Wiki_Rule {
*
*/

var $regex = '/ _\n/';
var $regex = '/([^\n])\n([^\n])/m';


/**
Expand All @@ -64,7 +65,7 @@ class Text_Wiki_Rule_newline extends Text_Wiki_Rule {

function process(&$matches)
{
return $this->addToken();
return $matches[1] . $this->addToken() . $matches[2];
}


Expand Down
10 changes: 2 additions & 8 deletions Text/Wiki/Rule/paragraph.php
Expand Up @@ -33,7 +33,6 @@

class Text_Wiki_Rule_paragraph extends Text_Wiki_Rule {


/**
*
* The regular expression used to find source text matching this
Expand All @@ -45,13 +44,8 @@ class Text_Wiki_Rule_paragraph extends Text_Wiki_Rule {
*
*/

function Text_Wiki_Rule_paragraph(&$obj, $name)
{
parent::Text_Wiki_Rule($obj, $name);
//$this->regex = "/^(?!{$this->_wiki->delim}).*?\n\n/m";
$this->regex = "/^.*?\n\n/m";
$this->_conf =& $this->_wiki->rules[$name]['conf'];
}
var $regex = "/^.*?\n\n/m";


/**
*
Expand Down
7 changes: 7 additions & 0 deletions Text/Wiki/Rule/prefilter.php
Expand Up @@ -64,6 +64,13 @@ function parse()
// add extra newlines at the top and end; this
// seems to help many rules.
$this->_wiki->_source = "\n" . $this->_wiki->_source . "\n\n";

// finally, compress all instances of 3 or more newlines
// down to two newlines.
$find = "/\n{3,}/m";
$replace = "\n\n";
$this->_wiki->_source = preg_replace($find, $replace,
$this->_wiki->_source);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Text/Wiki/Rule/table.php
Expand Up @@ -172,7 +172,7 @@ function process(&$matches)
$return .= $this->addToken(array('type' => 'table_end'));

// we're done!
return "\n$return";
return "\n$return\n";
}


Expand Down
6 changes: 3 additions & 3 deletions Text/Wiki/Rule/tighten.php
Expand Up @@ -21,7 +21,7 @@

/**
*
* This rule removes all newlines from the source text.
* The rule removes all remaining newlines.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
Expand All @@ -43,8 +43,8 @@ class Text_Wiki_Rule_tighten extends Text_Wiki_Rule {

function parse()
{
$this->_wiki->_source = str_replace("\n", "",
$this->_wiki->_source);
$this->_wiki->_source = str_replace("\n", '',
$this->_wiki->_source);
}
}
?>

0 comments on commit 72faf53

Please sign in to comment.