Firefox PHP

Module: BBcode version 2 (complete rewrite)

Posted by Maurice Makaay 
Module: BBcode version 2 (complete rewrite)
April 22, 2008 08:54AM
Please, download this one for testing only
This module will be available in Phorum 5.2.8 and up by default

During the MySQL conference, a lot of work was done on a total rewrite of the BBcode module. This has resulted in a new version of the module that in my opinion truly deserves its "version 2" tag. If you want to test out this new module, then download the package from this thread. Remember that this is a newly born and that some parts of the code were typed in after a few Guinness, so I can't promise you that it is a good idea to drop this on a production environment yet. But if you're willing to take a gamble here, I promise that I'll be at your service for quick bug fixes from the 3rd of May on (then I'll be back from my U.S. vacation).

For upgrading, first remove (or move) the existing mods/bbcode directory. Then unpack and install the new one in the mods/bbcode directory. Go to the admin interface to make Phorum update the module info (actually not really needed I think, but it's a good idea to do so anyway). Check out the module's settings screen for a few new items in there. That should be about it. Let me know if you run into upgrading problems, so I can take care of them in my code.

Some of the features for this new version:
  • The new module implements a real tokenizing parser, which is both very fast and allows for easy and flexable implementation of BBcode tags.
  • The parser can correct several problems like tags for which no close tag is provided and wrongly nested tags (this makes this version of the BBcode module extremely useful for those people that must/want to run their Phorum site using the application/xml content type).
  • It is now possible to cleanly escape tag arguments, making it possible to implement tags that look like [thetagname argument="Some [quoted] \"scary\" argument"]. This is for example very useful for the "quote" tag in combination with message authors that have names with brackets in them (not unfamiliar for people that run gaming forums, where often clan names in brackets are prefixed to the author names, e.g. "[MyCoolKlan] McShoot'3m". With the current BBcode module, we replace the brackets with other safe characters, which works but is not a really nice way to handle this.
  • The [email] tag was extended with a "subject" argument, so the subject for the mail link can be set.
  • (I hear you think: "Finally!!!") the [list] tag was implemented, which makes it possible to add itemized lists to the messages (just like the one that I use here for summing up the new features). An easy to use tool for the Editor Tools module was also implemented for this new tag. Thanks to the new parser code, even lists in lists are not problem at all!
  • A feature was added to make it possible to escape BBcode tags in a message by prepending them with a backslash, like \[email]. The tag will then not be interpreted by the parser, so it is shown as is in the message. The backslash is of course not shown in this case. This feature can be turned on and off on the module's settings screen, because not every forum will make use of it.
  • Preparations have been made to make it possible to cache the token list that is generated by the parser, which would make this module even faster than it already is. To give you an idea, here are some timings for a rather complicated message that I ran 1000 times through the module:

    0.0495929718018 init parser
    0.507103919983 tokenizer
    0.253345012665 renderer

    This comes down to 0.81 miliseconds per fully rendered message. But if we would put the tokenizer data in a cache, this would even go down to 0.30 miliseconds. Because I didn't really feel the difference between these timings :) I decided to not implement tokenizer caching for now.
  • Probably some other cool stuff that I forgot to mention.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce



Edited 5 time(s). Last edit at 06/05/2008 02:23AM by Maurice Makaay.
Attachments:
open | download - bbcode-2.0.7.tar.gz (55.8 KB)
open | download - bbcode-2.0.7.zip (85.2 KB)
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 02:45PM
I don't follow directions well. We are using it here on this site. Of course, the fact that I sat for 4 days and watched Maurice write most of it helps.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 02:50PM
Looks like a bug in the escaping here: [www.phorum.org]

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 04:24PM
Quote
mmakaay

* (I hear you think: "Finally!!!") the "list" tag was implemented, which makes it possible to add itemized lists to the messages which look better than the list that I am currently typing up in this message :-]

Time to test the new parser, thanks.

Edit: it's working good, though there appears to be extra blank lines between the different lists.

--
Bert Garcia - When all you have is a keyboard



Edited 2 time(s). Last edit at 04/22/2008 05:12PM by hcgtv.
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 06:26PM
It's not a bug, it's a feature ;-) There was a stand alone [code] tag in the message, which got nicely fixed by the parser by automatically closing it with [/code] at the very end of the message. Because the signature is part of the message body during parsing, this closing tag ended up after the signature. I changed the message to make use of the new \[escapedtag] feature to show what I was trying to say there.

I also had to go to the settings screen for the module and save its settings once to make all editor tools appear and work. Looks like I've got an upgrade path to take care of there. After saving the settings page, all looks fine and we have the list button in the editor tools here.

@hcgtv: I'll take a look at the spacing. I'm not sure when I'll be back online though. Heading towards Death Valley in a few and I'm not sure if we have internet over there.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce



Edited 1 time(s). Last edit at 04/22/2008 06:30PM by mmakaay.
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 06:49PM
Quote
mmakaay
I also had to go to the settings screen for the module and save its settings once to make all editor tools appear and work.

I can confirm this, once I saved the settings all was ok with the new module.

As for the spacing, I'll wait till you emerge from the desert :)

--
Bert Garcia - When all you have is a keyboard
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 08:00PM
Hmm, did this break bare URLs? My message above is not linked.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 08:10PM
Quote
hcgtv
though there appears to be extra blank lines between the different lists.

I think we need to add ol and ul to the list of tags that should have newlines stripped next to them. OL and UL are block level elements with natural margins by default.

Brian - Cowboy Ninja Coder - Personal Blog - Twitter
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 10:53PM
If I wrote a new function for the javascript lib that fixed the scrolling, selection and focus problems, would someone else be able to integrate it?

EDIT: That is, for the textarea toolbar :-)


If it moves, eat it. If it doesn't move, wait till it moves, then eat it



Edited 1 time(s). Last edit at 04/22/2008 11:02PM by optimal.
Re: Module: BBcode version 2 (complete rewrite)
April 22, 2008 11:27PM
Well, I'm busy working with similar code at the moment, so i've quickly compiled a page to demonstrate the functionality, hopefully you will find it useful!


If it moves, eat it. If it doesn't move, wait till it moves, then eat it
Attachments:
open | download - textarea helper.zip (1.7 KB)
Sorry, only registered users may post in this forum.

Click here to login