Update of /cvsroot/php-blog/serendipity/bundled-libs/Text/Wiki/Rule
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1804/Text/Wiki/Rule
Added Files:
blockquote.php bold.php code.php deflist.php delimiter.php
emphasis.php entities.php freelink.php heading.php horiz.php
html.php interwiki.php italic.php list.php newline.php
paragraph.php phpcode.php phplookup.php prefilter.php raw.php
revise.php strong.php superscript.php table.php tighten.php
toc.php tt.php url.php wikilink.php
Log Message:
Added PEAR:Text/Wiki (latest 0.8.2) bundled library
--- NEW FILE: blockquote.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: blockquote.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked as a
* blockquote, identified by any number of greater-than signs '>' at the
* start of the line, followed by a space, and then the quote text; each
* '>' indicates an additional level of quoting.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_blockquote 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((\>).*\n)(?!(\>))/Us';
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' =>
* 'start' : the start of a blockquote
* 'end' : the end of a blockquote
*
* 'level' => the indent level (0 for the first level, 1 for the
* second, etc)
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A series of text and delimited tokens marking the different
* list text and list elements.
*
*/
function process(&$matches)
{
// the replacement text we will return to parse()
$return = '';
// the list of post-processing matches
$list = array();
// $matches[1] is the text matched as a list set by parse();
// create an array called $list that contains a new set of
// matches for the various list-item elements.
preg_match_all(
'=^(\>+) (.*\n)=Ums',
$matches[1],
$list,
PREG_SET_ORDER
);
// a stack of starts and ends; we keep this so that we know what
// indent level we're at.
$stack = array();
// loop through each list-item element.
foreach ($list as $key => $val) {
// $val[0] is the full matched list-item line
// $val[1] is the number of initial '>' chars (indent level)
// $val[2] is the quote text
// we number levels starting at 1, not zero
$level = strlen($val[1]);
// get the text of the line
$text = $val[2];
// add a level to the list?
if ($level > count($stack)) {
// the current indent level is greater than the number
// of stack elements, so we must be starting a new
// level. push the new level onto the stack with a
// dummy value (boolean true)...
array_push($stack, true);
// ...and add a start token to the return.
$return .= $this->addToken(
array(
'type' => 'start',
'level' => $level - 1
)
);
$return .= "\n";
}
// remove a level?
while (count($stack) > $level) {
// as long as the stack count is greater than the
// current indent level, we need to end list types.
// continue adding end-list tokens until the stack count
// and the indent level are the same.
array_pop($stack);
$return .= $this->addToken(
array (
'type' => 'end',
'level' => count($stack)
)
);
$return .= "\n";
}
// add the line text.
$return .= $text . "\n";
}
// the last line may have been indented. go through the stack
// and create end-tokens until the stack is empty.
while (count($stack) > 0) {
array_pop($stack);
$return .= $this->addToken(
array (
'type' => 'end',
'level' => count($stack)
)
);
}
// we're done! send back the replacement text.
return "\n$return";
}
/**
*
* 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)
{
$type = $options['type'];
$level = $options['level'];
// set up indenting so that the results look nice; we do this
// in two steps to avoid str_pad mathematics. ;-)
$pad = str_pad('', $level, "\t");
$pad = str_replace("\t", ' ', $pad);
// starting
if ($type == 'start') {
return "$pad<blockquote>";
}
// ending
if ($type == 'end') {
return $pad . "</blockquote>\n";
}
}
}
?>
--- NEW FILE: bold.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: bold.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked for
* strong emphasis (bold) as defined by text surrounded by three
* single-quotes. On parsing, the text itself is left in place, but the
* starting and ending instances of three single-quotes are replaced with
* tokens.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_bold 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 = "/'''(()|[^'].*)'''/U";
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' => ['start'|'end'] The starting or ending point of the
* emphasized text. The text itself is left in the source.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A pair of delimited tokens to be used as a placeholder in
* the source text surrounding the text to be emphasized.
*
*/
function process(&$matches)
{
$start = $this->addToken(array('type' => 'start'));
$end = $this->addToken(array('type' => 'end'));
return $start . $matches[1] . $end;
}
/**
*
* 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)
{
if ($options['type'] == 'start') {
return '<b>';
}
if ($options['type'] == 'end') {
return '</b>';
}
}
}
?>
--- NEW FILE: code.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: code.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find sections marked as code
* examples. Blocks are marked as the string <code> on a line by itself,
* followed by the inline code example, and terminated with the string
* </code> on a line by itself. The code example is run through the
* native PHP highlight_string() function to colorize it, then surrounded
* with <pre>...</pre> tags when rendered as XHTML.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_code extends Text_Wiki_Rule {
/**
*
* The regular expression used to find source text matching this
* rule.
*
* @access public
*
* @var string
*
*/
var $regex = '/^(\<code\>)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';
/**
*
* Generates a token entry for the matched text. Token options are:
*
* 'text' => The full matched text, not including the <code></code> tags.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token number to be used as a placeholder in
* the source text.
*
*/
function process(&$matches)
{
$options = array('text' => $matches[2]);
return $this->addToken($options) . $matches[4];
}
/**
*
* 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)
{
// trim opening and closing whitespace
$text = trim($options['text']);
// convert tabs to four spaces
$text = str_replace("\t", " ", $text);
// convert entities
$text = htmlentities($text);
// done!
return "\n<pre><code>$text</code></pre>\n";
}
}
?>
--- NEW FILE: deflist.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: deflist.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked as a
* definition list. In short, if a line starts with ':' then it is a
* definition list item; another ':' on the same lines indicates the end
* of the definition term and the beginning of the definition narrative.
* The list items must be on sequential lines (no blank lines between
* them) -- a blank line indicates the beginning of a new list.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_deflist 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((:).*\n)(?!(:))/Us';
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' =>
* 'list_start' : the start of a definition list
* 'list_end' : the end of a definition list
* 'term_start' : the start of a definition term
* 'term_end' : the end of a definition term
* 'narr_start' : the start of definition narrative
* 'narr_end' : the end of definition narrative
* 'unknown' : unknown type of definition portion
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A series of text and delimited tokens marking the different
* list text and list elements.
*
*/
function process(&$matches)
{
// the replacement text we will return to parse()
$return = '';
// the list of post-processing matches
$list = array();
// start the deflist
$options = array('type' => 'list_start');
$return .= $this->addToken($options);
// $matches[1] is the text matched as a list set by parse();
// create an array called $list that contains a new set of
// matches for the various definition-list elements.
preg_match_all(
'/^(:)(.*)?(:)(.*)?$/Ums',
$matches[1],
$list,
PREG_SET_ORDER
);
// add each term and narrative
foreach ($list as $key => $val) {
$return .= (
$this->addToken(array('type' => 'term_start')) .
trim($val[2]) .
$this->addToken(array('type' => 'term_end')) .
$this->addToken(array('type' => 'narr_start')) .
trim($val[4]) .
$this->addToken(array('type' => 'narr_end'))
);
}
// end the deflist
$options = array('type' => 'list_end');
$return .= $this->addToken($options);
// done!
return $return;
}
/**
*
* 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)
{
$type = $options['type'];
$pad = " ";
switch ($type) {
case 'list_start':
return "<dl>\n";
break;
case 'list_end':
return "</dl>\n";
break;
case 'term_start':
return $pad . "<dt>";
break;
case 'term_end':
return "</dt>\n";
break;
case 'narr_start':
return $pad . $pad . "<dd>";
break;
case 'narr_end':
return "</dd>\n";
break;
default:
return '';
}
}
}
?>
--- NEW FILE: delimiter.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: delimiter.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find instances of the delimiter
* character already embedded in the source text; it extracts them and replaces
* them with a delimited token, then renders them as the delimiter itself
* when the target format is XHTML.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_delimiter extends Text_Wiki_Rule {
/**
*
* Constructor. Overrides the Text_Wiki_Rule constructor so that we
* can set the $regex property dynamically (we need to include the
* Text_Wiki $delim character.
*
* @param object &$obj The calling "parent" Text_Wiki object.
*
* @param string $name The token name to use for this rule.
*
*/
function Text_Wiki_Rule_delimiter(&$obj, $name)
{
parent::Text_Wiki_Rule($obj, $name);
$this->regex = '/' . $this->_wiki->delim . '/';
}
/**
*
* Generates a token entry for the matched text. Token options are:
*
* 'text' => The full matched text.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token number 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 $this->_wiki->delim;
}
}
?>
--- NEW FILE: emphasis.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: emphasis.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked for
* emphasis (italics) as defined by text surrounded by two single-quotes.
* On parsing, the text itself is left in place, but the starting and ending
* instances of two single-quotes are replaced with tokens.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_emphasis 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 = "/\/\/(()|.*)\/\//U";
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' => ['start'|'end'] The starting or ending point of the
* emphasized text. The text itself is left in the source.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A pair of delimited tokens to be used as a
* placeholder in the source text surrounding the text to be
* emphasized.
*
*/
function process(&$matches)
{
$start = $this->addToken(array('type' => 'start'));
$end = $this->addToken(array('type' => 'end'));
return $start . $matches[1] . $end;
}
/**
*
* 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)
{
if ($options['type'] == 'start') {
return '<em>';
}
if ($options['type'] == 'end') {
return '</em>';
}
}
}
?>
--- NEW FILE: entities.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: entities.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to convert HTML entities in the
* source text.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_entities extends Text_Wiki_Rule {
/**
*
* Simple parsing method to apply the rule.
*
* @access public
*
*/
function parse()
{
// first, decode any entities already in the text so that they
// don't get double-encoded
$trans_table = get_html_translation_table(HTML_SPECIALCHARS);
$this->_wiki->_source = strtr($this->_wiki->_source,
array_flip($trans_table));
// now encode all html special characters
$this->_wiki->_source = htmlspecialchars($this->_wiki->_source);
}
}
?>
--- NEW FILE: freelink.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: freelink.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked as a
* wiki freelink, and automatically create a link to that page.
*
* A freelink is any page name not conforming to the standard
* StudlyCapsStyle for a wiki page name. For example, a page normally
* named MyHomePage can be renamed and referred to as ((My Home Page)) --
* note the spaces in the page name. You can also make a "nice-looking"
* link without renaming the target page; e.g., ((MyHomePage|My Home
* Page)). Finally, you can use named anchors on the target page:
* ((MyHomePage|My Home Page#Section1)).
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_freelink extends Text_Wiki_Rule {
/**
*
* Constructor. We override the Text_Wiki_Rule constructor so we can
* explicitly comment each part of the $regex property.
*
* @access public
*
* @param object &$obj The calling "parent" Text_Wiki object.
*
* @param string $name The token name to use for this rule.
*
*/
function Text_Wiki_Rule_freelink(&$obj, $name)
{
parent::Text_Wiki_Rule($obj, $name);
$this->regex =
'/' . // START regex
"\\(\\(" . // double open-parens
"(" . // START freelink page patter
"[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
")" . // END freelink page pattern
"(" . // START display-name
"\|" . // a pipe to start the display name
"[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character
")?" . // END display-name pattern 0 or 1
"(" . // START pattern for named anchors
"\#" . // a hash mark
"[A-Za-z]" . // 1 alpha
"[-A-Za-z0-9_:.]*" . // 0 or more alpha, digit, underscore
")?" . // END named anchors pattern 0 or 1
"()\\)\\)" . // double close-parens
'/'; // END regex
}
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'page' => the wiki page name (e.g., HomePage).
*
* 'text' => alternative text to be displayed in place of the wiki
* page name.
*
* 'anchor' => a named anchor on the target wiki page
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
// use nice variable names
$page = $matches[1];
$text = $matches[2];
// get rid of the leading # from the anchor, if any
$anchor = substr($matches[3], 1);
// is the page given a new text appearance?
if (trim($text) == '') {
// no
$text = $page;
} else {
// yes, strip the leading | character
$text = substr($text, 1);
}
// set the options
$options = array(
'page' => $page,
'text' => $text,
'anchor' => $anchor
);
// return a token placeholder
return $this->addToken($options);
}
/**
*
* 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)
{
// get nice variable names (page, text, anchor)
extract($options);
if (in_array($page, $this->_wiki->pages)) {
// the page exists, show a link to the page
$href = $this->_wiki->view_url . $page . "#" . $anchor;
return "<a href=\"$href\">$text</a>";
} else {
// the page does not exist, show the page name and
// the "new page" text
$href = $this->_wiki->new_url;
return $text . "<a href=\"$href$page\">{$this->_wiki->new_text}</a>";
}
}
}
?>
--- NEW FILE: heading.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: heading.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked to
* be a heading element, as defined by text on a line by itself prefixed
* with a number of plus signs (+). The heading text itself is left in
* the source, but is prefixed and suffixed with delimited tokens marking
* the start and end of the heading.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_heading 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 = '/^(\+{1,6}) (.*)/m';
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' => ['start'|'end'] The starting or ending point of the
* heading text. The text itself is left in the source.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A pair of delimited tokens to be used as a
* placeholder in the source text surrounding the heading text.
*
*/
function process(&$matches)
{
$start = $this->addToken(
array(
'type' => 'start',
'level' => strlen($matches[1]),
'text' => $matches[2]
)
);
$end = $this->addToken(
array(
'type' => 'end',
'level' => strlen($matches[1])
)
);
return $start . $matches[2] . $end;
}
/**
*
* 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)
{
// get nice variable names (type, level)
extract($options);
if ($type == 'start') {
return "<h$level>";
}
if ($type == 'end') {
return "</h$level>\n";
}
}
}
?>
--- NEW FILE: horiz.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: horiz.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked to
* be a horizontal rule, as defined by four dashed on their own line.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_horiz 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 = '/^([-]{4,})$/m';
/**
*
* Generates a replacement token for the matched text.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A token marking the horizontal rule.
*
*/
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 "<hr />\n";
}
}
?>
--- NEW FILE: html.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: html.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked as
* HTML to be redndred as-is. The block start is marked by <html> on its
* own line, and the block end is marked by </html> on its own line.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_html 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 = '/^\<html\>\n(.+)\n\<\/html\>(\s|$)/Umsi';
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'text' => The text of the HTML to be rendered as-is.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text following the HTML block.
*
*/
function process(&$matches)
{
$options = array('text' => $matches[1]);
return $this->addToken($options) . $matches[2];
}
/**
*
* 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 $options['text'];
}
}
?>
--- NEW FILE: interwiki.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: interwiki.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_interwiki extends Text_Wiki_Rule {
/**
*
* Constructor. We override the Text_Wiki_Rule constructor so we can
* explicitly comment each part of the $regex property.
*
* @access public
*
* @param object &$obj The calling "parent" Text_Wiki object.
*
* @param string $name The token name to use for this rule.
*
*/
function Text_Wiki_Rule_interwiki(&$obj, $name)
{
parent::Text_Wiki_Rule($obj, $name);
$this->regex = '/([A-Za-z0-9]+):([\/=&~#A-Za-z0-9]+)/';
}
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'site' => The key name for the Text_Wiki interwiki array map, usually
* the name of the interwiki site.
*
* 'page' => The page on the target interwiki to link to.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'site' => $matches[1],
'page' => $matches[2]
);
// if not in the interwiki map, don't make it an interwiki link
if (isset($this->_wiki->interwiki[$options['site']])) {
return $this->addToken($options);
} else {
return $matches[0];
}
}
/**
*
* 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)
{
$site = $options['site'];
$page = $options['page'];
if (isset($this->_wiki->interwiki[$site])) {
$href = $this->_wiki->interwiki[$site];
} else {
$href = '';
}
if ($href != '') {
return "<a href=\"$href$page\">$site:$page</a>";
} else {
return "$site:$page";
}
}
}
?>
--- NEW FILE: italic.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: italic.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked for
* emphasis (italics) as defined by text surrounded by two single-quotes.
* On parsing, the text itself is left in place, but the starting and ending
* instances of two single-quotes are replaced with tokens.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_italic 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 = "/''(()|[^'].*)''/U";
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' => ['start'|'end'] The starting or ending point of the
* emphasized text. The text itself is left in the source.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A pair of delimited tokens to be used as a
* placeholder in the source text surrounding the text to be
* emphasized.
*
*/
function process(&$matches)
{
$start = $this->addToken(array('type' => 'start'));
$end = $this->addToken(array('type' => 'end'));
return $start . $matches[1] . $end;
}
/**
*
* 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)
{
if ($options['type'] == 'start') {
return '<i>';
}
if ($options['type'] == 'end') {
return '</i>';
}
}
}
?>
--- NEW FILE: list.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: list.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to find source text marked as
* a bulleted or numbered list. In short, if a line starts with '* ' then
* it is a bullet list item; if a line starts with '# ' then it is a
* number list item. Spaces in front of the * or # indicate an indented
* sub-list. The list items must be on sequential lines (no blank lines
* between them) -- a blank line indicates the beginning of a new list.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_list 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((\*|#) .*\n)(?! {0,}(\*|#))/Us';
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' =>
* 'bullet_start' : the start of a bullet list
* 'bullet_end' : the end of a bullet list
* 'number_start' : the start of a number list
* 'number_end' : the end of a number list
* 'item_start' : the start of item text (bullet or number)
* 'item_end' : the end of item text (bullet or number)
* 'unknown' : unknown type of list or item
*
* 'level' => the indent level (0 for the first level, 1 for the
* second, etc)
*
* 'count' => the list item number at this level. not needed for
* xhtml, but very useful for PDF and RTF.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A series of text and delimited tokens marking the different
* list text and list elements.
*
*/
function process(&$matches)
{
// the replacement text we will return
$return = '';
// the list of post-processing matches
$list = array();
// a stack of list-start and list-end types; we keep this
// so that we know what kind of list we're working with
// (bullet or number) and what indent level we're at.
$stack = array();
// the item count is the number of list items for any
// given list-type on the stack
$itemcount = array();
// populate $list with this set of matches. $matches[1] is the
// text matched as a list set by parse().
preg_match_all(
'=^( {0,})(\*|#) (.*)$=Ums',
$matches[1],
$list,
PREG_SET_ORDER
);
// loop through each list-item element.
foreach ($list as $key => $val) {
// $val[0] is the full matched list-item line
// $val[1] is the number of initial spaces (indent level)
// $val[2] is the list item type (* or #)
// $val[3] is the list item text
// how many levels are we indented? (1 means the "root"
// list level, no indenting.)
$level = strlen($val[1]) + 1;
// get the list item type
if ($val[2] == '*') {
$type = 'bullet';
} elseif ($val[2] == '#') {
$type = 'number';
} else {
$type = 'unknown';
}
// get the text of the list item
$text = $val[3];
// add a level to the list?
if ($level > count($stack)) {
// the current indent level is greater than the
// number of stack elements, so we must be starting
// a new list. push the new list type onto the
// stack...
array_push($stack, $type);
// ...and add a list-start token to the return.
$return .= $this->addToken(
array(
'type' => $type . '_start',
'level' => $level - 1
)
);
}
// remove a level from the list?
while (count($stack) > $level) {
// so we don't keep counting the stack, we set up a temp
// var for the count. -1 becuase we're going to pop the
// stack in the next command. $tmp will then equal the
// current level of indent.
$tmp = count($stack) - 1;
// as long as the stack count is greater than the
// current indent level, we need to end list types.
// continue adding end-list tokens until the stack count
// and the indent level are the same.
$return .= $this->addToken(
array (
'type' => array_pop($stack) . '_end',
'level' => $tmp
)
);
// reset to the current (previous) list type so that
// the new list item matches the proper list type.
$type = $stack[$tmp - 1];
// reset the item count for the popped indent level
$itemcount[$tmp + 1] = 0;
}
// add to the item count for this list (taking into account
// which level we are at).
if (! isset($itemcount[$level])) {
// first count
$itemcount[$level] = 1;
} else {
// increment count
$itemcount[$level]++;
}
// create a list-item starting token.
$start = $this->addToken(
array(
'type' => 'item_start',
'level' => $level,
'count' => $itemcount[$level]
)
);
// create a list-item ending token.
$end = $this->addToken(
array(
'type' => 'item_end',
'level' => $level,
'count' => $itemcount[$level]
)
);
// add the starting token, list-item text, and ending token
// to the return.
$return .= $start . $val[3] . $end;
}
// the last list-item may have been indented. go through the
// list-type stack and create end-list tokens until the stack
// is empty.
while (count($stack) > 0) {
$return .= $this->addToken(
array (
'type' => array_pop($stack) . '_end',
'level' => count($stack)
)
);
}
// we're done! send back the replacement text.
return $return;
}
/**
*
* 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)
{
// make nice variables (type, level, count)
extract($options);
// set up indenting so that the results look nice; we do this
// in two steps to avoid str_pad mathematics. ;-)
$pad = str_pad('', $level, "\t");
$pad = str_replace("\t", ' ', $pad);
switch ($type) {
case 'bullet_start':
return $pad . "<ul>\n";
break;
case 'bullet_end':
return $pad . "</ul>\n";
break;
case 'number_start':
return $pad . "<ol>\n";
break;
case 'number_end':
return $pad . "</ol>\n";
break;
case 'item_start':
return $pad . "<li>";
break;
case 'item_end':
return "</li>\n";
break;
default:
return '';
}
}
}
?>
--- NEW FILE: newline.php ---
<?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 |
// | li...@ph... so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pm...@ci...> |
// +----------------------------------------------------------------------+
//
// $Id: newline.php,v 1.1 2004/02/26 11:27:54 garvinhicking Exp $
/**
*
* This class implements a Text_Wiki_Rule to mark "hard" newlines in the
* source text.
*
* @author Paul M. Jones <pm...@ci...>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Rule_newline extends Text_Wiki_Rule {
/**
*
* The r...
[truncated message content] |