Beispiel #1
0
 public function SetUp()
 {
     $this->parser = new BBParser();
     $this->dumper = new BBDumper();
     $default = new BBCodeDefault();
     $default->addContentType('inline');
     $root = new BBCodeRoot();
     $root->addContentType('inline');
     $this->dumper->setDefaultHandler($default);
     $this->dumper->setRootHandler($root);
 }
Beispiel #2
0
$parser = new BBParser();
$dumper = new BBDumper();
const TYPE_INLINE = 'inline';
const TYPE_BLOCK = 'block';
const TYPE_LISTITEM = 'listitem';
$normalTypes = array(TYPE_INLINE, TYPE_BLOCK);
$inlineType = array(TYPE_INLINE);
// simple replacement
$bold = new BBCodeReplace('b', '<b>', '</b>', TYPE_INLINE, $inlineType);
$italic = new BBCodeReplace('i', '<i>', '</i>', TYPE_INLINE, $inlineType);
$underline = new BBCodeReplace('u', '<u>', '</u>', TYPE_INLINE, $inlineType);
$block = new BBCodeReplace('block', '<div>', '</div>', TYPE_BLOCK, $normalTypes);
$noparse = new BBCodeReplace('noparse', '<!-- noparse -->', '<!-- noparse end -->', TYPE_INLINE);
$dumper->addHandlers(array($bold, $italic, $underline, $block, $noparse));
// the default handler. It handles if a tag has no handler or is not permitted in a certain context.
$notag = new BBCodeDefault();
$notag->addContentTypes($normalTypes);
$dumper->setDefaultHandler($notag);
// the root handler. It bootstraps the application by allowing all content types in the parent node.
$root = new BBCodeRoot();
$root->addContentTypes($normalTypes);
$dumper->setRootHandler($root);
$list = new BBCodeCallback('list', TYPE_BLOCK, array(TYPE_LISTITEM), 'handle_list');
$list->trimInsideLeft = true;
$list->trimInsideRight = true;
$dumper->addHandler($list);
$listitem = new BBCodeReplace('*', '<li>', '</li>', TYPE_LISTITEM, $normalTypes);
$listitem->trimInsideLeft = true;
$listitem->trimInsideRight = true;
$dumper->addHandler($listitem);
// tell the parser that * tags don't have end tags.