• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Custom BBCode and Wysiwyg

Snog

Well-known member
#1
OK, here's my problem...

I've extended formatter/Base.php to add 3 new BBCodes and that works perfectly. The new BBCodes are displayed properly in posts.

When I edit a post with the custom BBCodes in it I get this...

badedit.jpg

I figured that could be solved by extending the formatter/Wysiwyg.php with this code..

Code:
<?php
 
class Snog_MyMod_BbCode_Formatter_Wysiwyg extends XFCP_Snog_MyMod_BbCode_Formatter_Wysiwyg
{
 
    public function getTags()
    {
        if ($this->_tags !== null)
        {
            return $this->_tags;
        }
 
        $tags = parent::getTags();
 
        $tags['mainbox'] = array(
            'hasOption' => false,
            'callback' => array($this, 'renderTagMainbox')
        );
 
        $tags['lbox'] = array(
            'hasOption' => false,
            'callback' => array($this, 'renderTagLbox')
        );
 
        $tags['rbox'] = array(
            'hasOption' => false,
            'callback' => array($this, 'renderTagRbox')
        );
 
        foreach ($tags AS $tagName => &$tag)
        {
            if (in_array($tagName, $this->_undisplayableTags))
            {
                $tag['callback'] = array($this, 'renderTagUndisplayable');
                unset($tag['trimLeadingLinesAfter'], $tag['stopLineBreakConversion']);
            }
            else if (isset($this->_tagReplacements[$tagName]))
            {
                $tag = array_merge($tag, $this->_tagReplacements[$tagName]);
                if (isset($this->_tagReplacements['replace']))
                {
                    unset($tag['callback']);
                }
            }
        }
 
        return $tags;
    }
 
    public function renderTagMainbox(array $tag, array $rendererStates)
    {     
        $text = $this->renderSubTree($tag['children'], $rendererStates);
        return '<div>' . $text . '</div>';
    }
 
    public function renderTagLbox(array $tag, array $rendererStates)
    {     
        $text = $this->renderSubTree($tag['children'], $rendererStates);
        return '<div style="width:200px;float:left;display:block;vertical-align:top;">' . $text . '</div>';
    }
 
    public function renderTagRbox(array $tag, array $rendererStates)
    {     
        $text = $this->renderSubTree($tag['children'], $rendererStates);
        return '<div class="message messageText" style="height:auto;text-align:left;vertical-align:top;overflow:hidden;">' . $text . '</div>';
    }
}
When that code is active, all formatting with the custom BBCodes in the post is lost in the editor.

Am I missing something, or doing something incorrectly?
 
Last edited:

Snog

Well-known member
#3
Isn't this behaving the same way way as if you edit a post that contains e.g. quote and code tags?

Or am I missing something?
I suppose it would be the same as that.

But, I anticipated the formatting to be viewable in the formatted state in the editor. Like the bold BBCode.

That's what I would really like to accomplish.
 

Chris D

XenForo developer
Staff member
#4
I'm not actually sure what's involved in that.

There must be a reason why block tags are displayed as they are as it is. It would be cool to be able to WYSIWYG them as well. But there must be a good reason why it isn't done like that already for other BB Codes.

Maybe it involves edits to Redactor more than the BB Code formatter.
 

Snog

Well-known member
#5
I never thought of looking at Redactor. It just might be in there. If that's the case, I'll live with it the way it is.