Hi,

I realized after a while that the existing BBCode module for Drupal didn't fit my requirements, mainly because it is practically impossible to add custom tags to it. Some CMS systems (like the Invision forum) already offer this feature, so I looked at what would be necessary to add it as a Drupal module.

I've called this xbbcode, for "extensible BBCode".

My idea for the functionality would be this:

- The module would provide a settings form to the administrator, who can create new tags (stored in a table), specifying an identifier (like "url") and a replacement text (like '"<a href="{option}">{content}&lt/a>'), as well as a few options and help texts.
- The module would provide a new "custom hook" (named "xbbcode") which it would invoke on startup. Through this hook, other modules would have the ability to add tags as well.
- Tags could be generated dynamically using evaluated PHP code (or, for modules, a callback function).

The xbbcode hook emulates the behavior of standard Drupal hooks like "filter" and "block" - an $op parameter decides what action is requested, a $delta parameter decides what tag is being used, and so on.

-------------

Now, I've finished a kind of prototype. Formalizing, testing and cleaning the code so it is ready for CVS would take a lot more time, so first I'd like to know: Is there any demand for this? Or (oh no!) has it been done already, and I've reinvented the wheel?

--
Aran

Comments

bradlis7’s picture

It would be better to submit patches to the current bbcode module... if your module is based on the bbcode module, it wouldn't be too hard (using the diff command). I'm all for the idea, but I think it would be better to change the current one.

--
Bradlis7.com

cburschka’s picture

Technically, it can replace it when matured, but the structure and code of the module is completely different (different enough for "diff" to be useless). The only way they're related is that the functionality is roughly similar.

Consider it: bbcode does a series of "hard-coded" regular expression replacements. This module does not hard-code anything at all, it only uses the tags set in the table or by other modules. This means that if you install xbbcode, you still need to create all the "standard" tags like [b], [i], [s] and [url]. The bare installation of xbbcode has no built-in tags (which makes it more flexible, too).

Here's an idea: If xbbcode does become an established module, bbcode could stop using its hardcoded regular expressions and instead use the xbbcode API hook to provide all the standard tags.

For now, I've had good results with using both in series - my Input Format first runs through the xbbcode filter and then through bbcode to parse any tags xbbcode didn't know.

cburschka’s picture

I've been able to use the version linked below for my blog. It doesn't have any tags out of the box, but it provides a settings form (/admin/settings/xbbcode/tags) which allows the creation of tags.

This is not for production use. I can't stress that enough. Firstly, it's very slow as caching is still disabled. Second, the help pages don't yet exist. I've tested this only with PHP 5 so far.

As a rule of thumb, don't install it until you've read and understood most of the code - and even then, only at a test site.

http://ermarian.net/resources/drupal-addons/xbbcode-5.x-0.1.tar.gz

--
Aran

vm’s picture

I certainly think this would have great value in the community and let users feel like they can get away from the BIG WYSIWYG editors they have come to rely on.

would be REALLY nice, if bbcodes buttons could be role based : )

cburschka’s picture

So far I've been thinking more about enabling or disabling tags based on input formats. Technically, this would be enough - input formats could then be enabled for different roles.

vm’s picture

agreed, didn't think of that angle.

cburschka’s picture

The last version I posted here had some problems with dynamic tags (which added backslashes to quotes) and self-closing tags (which didn't work at all due to a misspelled variable). This one fixes these, and also allows multiple attributes (as in [quote author=you date=today] rather than [quote=you]).

I'll apply for a CVS account by the end of today so this project can be properly included on the site...

Current testing version is here:

http://ermarian.net/resources/drupal-addons/xbbcode-5.x-0.1.1.tar.gz

(note: Tables have changed slightly and there is no update hook since the first one was only a prototype. So the options are to re-install from scratch or just manually delete and recreate the table as described in hook_install.)

Also, since the bare engine is useless without some actual tags (and nobody wants to add all the basic [i] and [b] ones themselves), this additional module will use the XBBCode API to provide basic tags. In combination, the two modules can already provide most of the functionality that the standard BBCode has.

http://ermarian.net/resources/drupal-addons/basicbb-5.x-0.1.tar.gz

--
Arancaytar

cburschka’s picture

The infrastructure of the module has been improved somewhat, and the module now allows disabling and weighting tags. Also, if multiple modules implement a tag (or the tag is both handled by a module and added as a custom tag by the admin), it is possible to choose which module should be used. All these settings can be adjusted separately for each input format.

My CVS application hasn't yet been processed (I'm not sure how long this usually takes, so I'll wait a full week before I ask for some follow-up), so here's the new download at my site:

http://ermarian.net/resources/drupal-addons/xbbcode-5.x-0.1.2.tar.gz

--
Arancaytar

WhatTheFawk’s picture

Are you still working on this I couldn't find a project page for it. I'm very interested in this also as I just started looking through WYSIWYG editors and user end bbcode options, I didn't know BBCode.module was so hard to update and customize, (I haven't tried yet though). I will try out your xBBCode in a little bit, but I'm wondering if this is like Rep[lacement]Tags another module I'm about to try. I'm pretty sure it can be used to make custom BBCode or any type of format tag you need. It even allows custom tags per user, etc.

http://drupal.org/project/reptag
http://www.profix898.de/files/drupal/reptag/reptag_page.png

If this is a lot like that maybe you can work with them, co-maintain that mod or merge the two modules.

cburschka’s picture

Yes, it does roughly the same, even though the technical concept/approach is different. I haven't yet tried it, so I can't say whether my module offers anything reptag doesn't (and couldn't easily implement).

However, from the info page it appears that reptag also provides an API for other modules to export their tags (I'll have to test that too), which is easily the most important feature of my module too. I haven't yet seen how it handles nested tags and how much freedom is given in how the tag is processed.

However, if both of those work as well or better than my approach, then it appears I have nothing to add; in that case I'll just dump this and use reptag on my site instead.

--Aran