Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 173 → Rev 174

/trunk/api/text/wiki_wikini/Wikini.class.php
21,7 → 21,7
// | along with Foobar; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: Wikini.class.php,v 1.1 2004-11-23 17:25:38 jpm Exp $
// CVS : $Id: Wikini.class.php,v 1.2 2004-11-25 15:36:41 jpm Exp $
/**
* Classe configurant le formatage pour Wikini.
*
36,7 → 36,7
//Autres auteurs :
*@author Aucun
*@copyright Tela-Botanica 2000-2004
*@version $Revision: 1.1 $ $Date: 2004-11-23 17:25:38 $
*@version $Revision: 1.2 $ $Date: 2004-11-25 15:36:41 $
// +------------------------------------------------------------------------------------------------------+
*/
 
71,8 → 71,8
*
*/
var $rules = array(
'Table', // Tableaux
'Code', // Inclusion de code avec coloration syntaxique
'Delimiter', // Type de retour à la ligne
'Emphasis', // Italique
'Freelink', // Nom de Page qui ne sont pas au format Wiki
'Heading', // Titre
84,10 → 84,10
'Tighten', // Réduit les lignes vide si on en a 3 ou plus consécutives
'Raw', // Inclusion de HTML et non traitement du contenu par les règles de formatage. Modifié par rapport à l'original de Text_Wiki
'Revise', // Suppression de texte. Modifié par rapport à l'original de Text_Wiki
'Table', // Tableaux
'Tt', // Texte à espacement fixe
'Url', // Inclusion d'url dont les url d'images
'Strong'// Gras
'Strong',// Gras
'Include'// Action Include
);
/**
*
98,7 → 98,7
* @var string
*
*/
var $delim = "\xFF";
var $delim = 12;
function Text_Wikini()
{
114,6 → 114,152
$this->fixPath(dirname(__FILE__)) . 'Render/'
);
}
/**
*
* Renders tokens back into the source text, based on the requested format.
*
* @access public
*
* @param string $format The target output format, typically 'xhtml'.
* If a rule does not support a given format, the output from that
* rule is rule-specific.
*
* @return string The transformed wiki text.
*
*/
function render($format = 'Xhtml')
{
// the rendering method we're going to use from each rule
$format = ucwords(strtolower($format));
// the eventual output text
$output = '';
// when passing through the parsed source text, keep track of when
// we are in a delimited section
$in_delim = false;
// when in a delimited section, capture the token key number
$key = '';
// load the format object
$this->loadFormatObj($format);
// pre-rendering activity
if (is_object($this->formatObj[$format])) {
$output .= $this->formatObj[$format]->pre();
}
// load the render objects
foreach (array_keys($this->parseObj) as $rule) {
$this->loadRenderObj($format, $rule);
}
// pass through the parsed source text character by character
$k = strlen($this->source);
for ($i = 0; $i < $k; $i++) {
// the current character
$char = $this->source{$i};
// are alredy in a delimited section?
if ($in_delim) {
// yes; are we ending the section?
if ($char == chr($this->delim)) {
// yes, get the replacement text for the delimited
// token number and unset the flag.
$key = (int)$key;
$rule = $this->tokens[$key][0];
$opts = $this->tokens[$key][1];
$output .= $this->renderObj[$rule]->token($opts);
$in_delim = false;
} else {
// no, add to the dlimited token key number
$key .= $char;
}
} else {
// not currently in a delimited section.
// are we starting into a delimited section?
if ($char == chr($this->delim)) {
// yes, reset the previous key and
// set the flag.
$key = '';
$in_delim = true;
} else {
// no, add to the output as-is
$output .= $char;
}
}
}
// post-rendering activity
if (is_object($this->formatObj[$format])) {
$output .= $this->formatObj[$format]->post();
}
// return the rendered source text.
return $output;
}
/**
*
* Add a token to the Text_Wiki tokens array, and return a delimited
* token number.
*
* @access public
*
* @param array $options An associative array of options for the new
* token array element. The keys and values are specific to the
* rule, and may or may not be common to other rule options. Typical
* options keys are 'text' and 'type' but may include others.
*
* @param boolean $id_only If true, return only the token number, not
* a delimited token string.
*
* @return string|int By default, return the number of the
* newly-created token array element with a delimiter prefix and
* suffix; however, if $id_only is set to true, return only the token
* number (no delimiters).
*
*/
function addToken($rule, $options = array(), $id_only = false)
{
// increment the token ID number. note that if you parse
// multiple times with the same Text_Wiki object, the ID number
// will not reset to zero.
static $id;
if (! isset($id)) {
$id = 0;
} else {
$id ++;
}
// force the options to be an array
settype($options, 'array');
// add the token
$this->tokens[$id] = array(
0 => $rule,
1 => $options
);
// return a value
if ($id_only) {
// return the last token number
return $id;
} else {
// return the token number with delimiters
return chr($this->delim) . $id . chr($this->delim);
}
}
}
 
// +------------------------------------------------------------------------------------------------------+
125,7 → 271,10
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.1 2004/11/23 17:25:38 jpm
* Début classe PEAR WIKI pour la syntaxe Wikini.
*
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>