Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 8

6apxatCurtisOdenestlf349141590tc74422 +2 guests

Extension: BBCodeParser

Tired of waiting for BetterBBCode to get better? Then give the new BBCodeParser a go. It works well with the BBInsertBar and has great formatting flexibility supporting even more BBCode. It will happily sit along side other text formatters as well.

*** Nested Lists!
*** Hacked in support for YouTube video via the [youtube][/youtube] tag
*** Easy to update to newer versions of the PEAR HTML_BBCodeParser
*** Requires PEAR in your PHP installation

To do:
+ Create Video.php filter to include other video sites such as Google, MSN SoapBox, Metacafe et al and move the ugly hack for YouTube to there to make it nice and smart.
+ Add options screen to make the tags configurable, ie. arbitarily disable any BBCode tags you dislike. Initially, this could work broadly by disabling whole filters.

This extension uses Seth Price's version of the PHP PEAR HTML_BBCodeParser which fixes many of the official bugs listed on the official site.
«1

Comments

  • Posts: 403
    hey stash. i got a white/blank screen when i activated this. (trying to view post.php).
  • Posts: 2,610
    No error messages of any kind?

    How blank? Just where the content area, or even the header and navs?

    Also, which other extensions do you have installed and activated?
  • Posts: 2,610
    Anyone else having this trouble?
  • Posts: 182
    Works fine for me, no error, no blank pages. But when I change from BetterBBCode to BBCodeParser, I loose many line breaks in comments, rendering them very hard to read!
  • Posts: 182
    But when used together with AutoP, it works exactly as expected! Very nice! Thank you!
  • Posts: 2,610
    Ahhhhhhhhhhhhh. Ah yes. I'm not sure where, how or why, but the later HTML_BBCodeParser that I'm using does things slightly differently to the older version used in BetterBBCode. But like you say, AutoP fixes all ;) And regarding it working well with AutoP... well I did them at the same time image Thanks for letting me know that it works.

    Circuit, if you give us some more information we might be able to track the problem down.
  • Posts: 13
    I'll test this extension... only a (php newbie) question: I'm pretty sure my host provider has not installed PEAR... what can I do?
    Can I include it in my Vanilla dir? (I can't install php packages on the server)
  • Posts: 2,610
    I'm a PHP noob myself, so I wouldn't know the answer to that. Anyone have the answer?
  • Posts: 2,610
    emilime, I'd ask your host if they would be willing to install PEAR. Did you try it an see if it worked anyway? If it did, PEAR's installed.
  • Posts: 182
    Hi! Im using BBCodeParser together with AutoP, and get into trouble with nested quotes. it doesn't open a second level of quotation, but it closes the first, when the second is ended. [quote]Some Text [quote]Second Quotetation...[/quote] more text [/quote] is rendered as: <blockquote>Some Text [quote]Second Quotetation...</blockquote> more text [/quote] Bye Tiggr
  • Posts: 921
    I don't really know anything about the context, but here's how you could go about changing nested quotes into their html equivelent:
    $out = $text;
    do
    {
    $text = $out;
    $out = preg_replace(
    '/\[quote(=([^\]]*?))?\]((.*?)|(?R))\[\/quote\]/is',
    '<blockquote cite="\\2">\\3</p></div></blockquote>',
    $text
    );
    }
    while($out != $text);
    (where $text holds the comment text)
  • Posts: 2,610
    Tiggr, that's a juicy one, thanks. I don't have a solution to that right now, but I'll get onto it pronto.

    SirNot, you're too clever for me :P
  • Posts: 2,610
    Hehe, check this out...

    Here's some random code
    <code>and this lot's in a nested code


    The above is actually this:
    Hehe, check this out...
    <code>
    Here's some random code
    <code>and this lot's in a nested code</code>
    </code>

    There's a basic problem with this. How do the machine know to not close the first one? It doesn't know there will be a second one. That's why the HTML version screws up as well. For the BBCode version, I reckon something like a new [bbcode][/bbcode] tag would solve this problem. What this tag would need to do is prevent the parser from parsing any more BBCode until the [/bbcode] tag comes in. Of course, that means you can't have nested [bbcode] tags, but... are there other solutions to this that I can't see?
  • Posts: 921
    I don't quite follow all of that, but assuming you're asking how to manage nested tags, just use a regular expression with the recursive directive ((?R)).

    ...and the html formatter screws up your code example because a) it dosn't allow code tags to be nested (although in this case they did manage to come out like that as a consequence of the 'tag police') and b) it automatically converts all html within code tags to their entity equivelents.
  • Posts: 2,610
    Thanks SirNot. There's just one problem - all that you just said about regex went way over my head. I'm really very *very* new to PHP, JS and all the stuff that goes with them like RegEx - I have a LOT to learn.

    Regarding your a) comment, what's this about the "tag police" (I feel like I've missed part of a discussion here somewhere) and how are they causing the strangeness with Html Formatter?

    As to b), how does converting to entity equivalents make that example display like that?

    I really appreciate your input on this as you obviously have a far greater understanding of these things than I do. So if you would be so kind as to continue, I would really appreciate it :)
  • Posts: 182
    Hi and thank you! The strange thing is: I'm shure, it worked fine with BetterBBCode! :-( Would be nice to have nested quotings...
  • Posts: 921
    The 'tag police' is a sort of half-arsed html tidier in the html formatter, which tries to make sure there aren't any stray opening or closing tags. What happened there was that the second opening code tag was escaped because it was between an opening code tag and the nearest ending one. Subsequently, the second closing code tag was left orphaned, so the html formatter attempted to fix that by adding an opening code tag to the beginning of the comment. As for regular expressions, I've found this page to be quite useful: http://php.net/manual/en/reference.pcre.pattern.syntax.php ; I already showed you how you could apply a recursive regular expression to nested bbcode in my earlier comment.
  • Posts: 2,610
    Tiggr, I will get this fixed. Please just be patient :)

    SirNot, thanks again. Just attempting to wrap my head around it all!
  • Posts: 182
    No problem, I can wait... ;-) I had a look into it by my self, but I had no idea how to fix! I'm very thankful for the many good extensions you do for vanilla. So no hurry! Keep on your great work.
  • Posts: 521
    When it comes to tags inside a code block, that's even more problematic, isn't it? Since the tags inside the code block shouldn't get parsed (or perhaps that makes it easier?). The behaviour I'd expect from code tags (with the example above) would be:
    Here's some random code
    <code>and this lot's in a nested code</code>
  • Posts: 2,610
    That's right bjrn. I believe that is what the result should be, so I'm looking at how to get that and how SirNot's recursive (R) can help me :)
  • Posts: 921
    Well then you get into trying to determine what is code and what isn't. Suppose they had this in their code tags: printf("</code>");? It's not a nested code tag pair, but it also isn't the end of the code.

    I'd rather keep it (the html formatter) simple and not try to second guess the poster.
  • Posts: 2,610
    I complete agree SirNot, but then how do you present that code?

    In the case of BBCode, I suppose you can always do it in the HTML formatter and vice-versa...
  • Posts: 25
    Is there a way to make this a bit more user friendly? Eg always presume there's going to be bbcode inside the post, rather than making a person click "bbcode" under the post box.. and/or, also, when the bbcode gets processed, make it so the linebreaks are NOT stripped out? Would make a lot more sense imo.. or if someone can just point me in the right direction on how to do this to mine, it'd be greatly appreciated.. as i'd rather every post was processed as having bbcode but linebreaks are not stripped out.
  • Posts: 25
    Ok the only thing I need now, if someone can help me, is to make linebreaks still work when the post is parsed as bbcode. Rather than making users have to put [br] for each new line etc. Is this possible? It's the only thing stopping me from making my site live right now. I don't want to have to explain to users why they have to use [br] tags if they want to do something as simple as post a link. I've got the forum automatically parsing every post as bbcode, which works fine.. just the linebreak bit needs fixing.
  • Posts: 2,610
    There is an option to make BBCode the default, but I haven't included it so far. When I get around to making a settings screen for this extension I'll pop it in there so you can simply toggle it on and off. Try adding this:// set the default formatter to BBCode
    $Context->Configuration['DEFAULT_FORMAT_TYPE'] = 'BBCode';

    above/before line 13:class AutoPFormatter extends StringFormatter {
    Regarding the line break stripping, that is just a function of this version of the parser. BBCodeParser strips everything out and pretty much all the other formatters whack extra ones in all over the place, so that's why AutoP exists. Install and enable AutoP and see if that makes things better for you.
  • Posts: 25
    That AutoP extension worked perfectly! Thank you heaps.. I think everything is pretty much how I like it now.. cheers :)
  • Posts: 2,610
    You're welcome, glad to be of service :)

    Regarding the whole default formatter thing, do people think it would be rude to have the formatter default itself by default? What happens when you have two formatters that do the same thing?

    Let me know, thanks :)
  • Posts: 182
    Hi!
    When it comes to tags inside a code block, that's even more problematic, isn't it?
    This is a second problem. But no for me, because nobody is posting code inside my forums. ;-)

    Solving the nested quote problem would be enough for me, and perhabs for many others too?

    Posting code is a more sophistcated problem, because of all the nice things we like to have for code: line numbers, syntax hightligthning, nice breaks... perhabs this should be handled by a diffrent extension?

    Bye
    Tiggr
  • Posts: 2,610
    I'm looking at the nested quotes first and the code second.
This discussion has been closed.