XF 2.1 Add BB code option

Mr. Jinx

Well-known member
I created a small addon that adds an extra option to the TABLE BB code.
This works fine, but the problem is that when you are in the BB code editor and switch view (toggle BB code), the extra option gets stripped.

So when you have:
Code:
[TABLE=collapse]
[TR][TH]Header 1[/TH][TH]Header 2[/TH][/TR]
[TR][TD]Content 1[/TD][TD]Content 2[/TD][/TR]
[/TABLE]

...the 'collapse' part is removed when you switch BB code view in the editor:
Code:
[TABLE]
[TR][TH]Header 1[/TH][TH]Header 2[/TH][/TR]
[TR][TD]Content 1[/TD][TD]Content 2[/TD][/TR]
[/TABLE]

I did the following extensions:

XF\BbCode\Renderer\EditorHtml:
Code:
class EditorHtml extends XFCP_EditorHtml
{
    protected function renderFinalTableHtml($tableHtml, $tagOption, $extraContent)
    {
                $options = \XF::options();
                $defaultWidth = $options->MrJinx_TableTweak_Default;

                if ($tagOption == 'collapse' or ($defaultWidth == 'collapse' and $tagOption != 'full'))
                {
                        $output = "<table>$tableHtml</table>";
                }
                else
                {
                        $output = "<table style='width: 100%'>$tableHtml</table>";
                }


        if (strlen($extraContent))
        {
            $output .= "<p>$extraContent</p>";
        }

        return $output;
    }
}

XF\BbCode\Renderer\Html:
Code:
class Html extends XFCP_Html
{

    protected function renderFinalTableHtml($tableHtml, $tagOption, $extraContent)
    {
        $options = \XF::options();
        $defaultWidth = $options->MrJinx_TableTweak_Default;

        if ($tagOption == 'collapse' or ($defaultWidth == 'collapse' and $tagOption != 'full'))
        {
            return "<div class=\"bbTable\">\n<table>$tableHtml</table>\n$extraContent</div>";
        }
        else
        {
            return "<div class=\"bbTable\">\n<table style='width: 100%'>$tableHtml</table>\n$extraContent</div>";
        }
    }


}

Anyone know why the option gets stripped? I can't find it..
 
Last edited:
Back
Top Bottom