How to create an additional custom tag
webdzinez - March 10, 2008 - 19:24
| Project: | Bbcode |
| Version: | HEAD |
| Component: | BBCode Tags |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed |
Jump to:
Description
Great module!
I am working for a math forum and they want to install a custom bbcode to allow latex formulas. I have to use the following:
tag name: [math] [/math]
replacement: ?{param}
And thats it. How would I be able to achieve this?
Thanks a bunch!

#1
I tried hacking bbcode-filter.inc, but I think I'm overlooking something, it doesn't changes anything.... But there are the defenitions of the supported tags.
#2
Here is my addition:
// begin processing for [spoiler]if (stristr($body, '[spoiler=') !== FALSE) { // prevent useless processing
$arr = array(
'tag' => 'spoiler',
'pattern' => '\\[spoiler\\](.*?)\\[/spoiler\\]',
'replacement' => '<a href="#" class="spoiler">Spoiler: <span>$1</span></a$
'text' => $body);
$body = _bbcode_replace_nest_tag($arr);
} // end processing for [spoiler]
+ Additional CSS code in my template
I think this should work... But I think I've to enable it somehow...
#3
Ablank, if you are proposing a new tag, please submit a patch for it.
#4
I would be proud to submit a patch because its a really nessary tag and I want to provide it with the world, BUT FIRST IT SHOULD WORK ;)
Any ideas are welcome :)
#5
no help on the syntax?
#6
Unfortunately I don't have time to help you with the code. However, when done, you are welcome to submit a patch for it.
#7
I have patched my own web, and works fine for me: http://www.razonaurea.com. It makes use of the service http://www.texify.com
Please, test it and submit this patch.
All changes are in bbcode-filter.inc:
<?php
'#\[youtube\]([0-9a-zA-Z_\-]+)\[/youtube\]#si' => '<object width="425" height="366"><param name="movie" value="http://www.youtube.com/v/\\1"></param><embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" width="425" height="366"></embed></object>',
+ '#\[math(?::\w+)?\](?:[\r\n])*(.*?)\[/math(?::\w+)?\]#sie' => '_bbcode_math_tag(\'\\1\')',
// Table tags
'#\[table\](.+?)\[/table\]#si' => '<table class="bb-table">\\1</table>',
?>
And after _bbcode_php_tag function:
<?php+ function _bbcode_math_tag($text = NULL) {
+ return '<img alt="'.$text.'" src="http://texify.com/img/'.urlencode(str_replace('+', '%2B', $text)).'.gif" />';
+ }
?>
Thank u,
Ismael