コード例 #1
0
ファイル: BBDumperTest.php プロジェクト: Ralle/BBCode-Parser
 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);
 }
コード例 #2
0
ファイル: main.php プロジェクト: Ralle/BBCode-Parser
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.
$parser->tagsWithNoEnd[] = '*';
// the callback function for the list tag. This function modifies the structure of the nodes in the subtree of the tag. Each "li" list item has no children, but they should. Therefore we move all the following siblings into the last seen "li".
// we also look at the first item and see if it is either empty after trim() or else we create a new "li" and add it to it.
function handle_list(BBNode $node, BBCode $handler)