Edit report at https://bugs.php.net/bug.php?id=59274&edit=1
ID: 59274
Comment by: hiram_ at gmx dot net
Reported by: hiram_ at gmx dot net
Summary: Add parser callback for non BBcode strings
Status: Open
Type: Feature/Change Request
Package: bbcode
Operating System: Solaris
PHP Version: 5.3.2
Block user comment: N
Private report: N
New Comment:
I believe that a callback at the same point were smileys are parsed would
suffice. At least if i understand the code correctly.
Previous Comments:
------------------------------------------------------------------------
[2011-06-18 11:10:08] hiram_ at gmx dot net
On second thought: a default handler would not be enough since given this
example
"hello [b]this is [i]bold[/i] not italic[/b]"
it would be called with
"bold",
"this is <em>bold</em> not italic" and
"hello <strong>this is <em>bold</em> not italic</strong>"
instead of "hello", "this is ", "bold" and "not italic"
so my handler would only be called with leaf nodes (if you consider every text
in a tag seperated by another tag as a seperate node like in xml happens)
This is usefull to have for example nl2br as a default text content handler and
be able to disallow it in certain tags
------------------------------------------------------------------------
[2010-12-02 18:59:02] hiram_ at gmx dot net
Yes, i think that would suffice.
------------------------------------------------------------------------
[2010-06-20 11:29:36] xdecock at gmail dot com
it will be a default content handling?
better to add a function bbcode_set_default_handler() IMHO,
if this is ok for you, i can make a publication in a few hours.
Xavier.
------------------------------------------------------------------------
[2010-06-20 09:57:23] hiram_ at gmx dot net
Description:
------------
I want to replace newlines with <br /> while parsing BBcode and do some more
special replacements. But since our youtube tag replacement includes some
newlines, those are replaced by <br /> to.
Is it possible to add an generic content handler?
so for example for the string "hello [b]this[/b] is [i]bold[/i]"
and the parser below
that handler would get called with "hello ", " is " and "this"
Reproduce code:
---------------
<?php
$string = "hello [b]this[/b] is [i]bold[/i]";
$BBCode = array(
''=> array(
'type' => BBCODE_TYPE_ROOT),
'generic'=> array(
'type' => BBCODE_TYPE_GENERIC,
'content_handling'=> 'contentHandler'),
'b'=> array(
'type' => BBCODE_TYPE_NOARG,
'open_tag'=> '<strong>',
'close_tag'=> '</strong>'),
'i'=> array(
'type' => BBCODE_TYPE_NOARG,
'child' => '!generic',
'open_tag'=> '<em>',
'close_tag'=> '</em>'),
);
$BBHandler = bbcode_create($BBCode);
bbcode_parse($BBHandler, $string);
function contentHandler($content)
{
echo "'$content'\n";
}
?>
Expected result:
----------------
'hello '
'this'
' is '
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=59274&edit=1