MyBB Community Forums

Full Version: [Request] BBCode alignment style MyCodes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello.

You see, my forum used to be hosted in a another site with phpBB forum software. That means that the alignment code was [center] [left] [right], unlike MyCode defaults that are [align=center] [align=left] [align=right].

Now we are moving to a MyBB platform, and we are also moving our valuable topics.

My users tend to simply copy & paste the content of such topics, and most of them are unaware of the alignment difference.

I would like to request for custom MyCode to accept alignment like
[center] [/center]
[right] [/right]
[left] [/left]

I am still keeping the [align=center] style too. Basically I want my board to support both styles.

I know this sounds pretty simple, but I fear to write the wrong code and screw everything, for I'm not very experienced on this.

Thanks.
On the AdminCP, go to Configuration, then MyCode (on the left side).

Add this MyCode.
Regular expresion:
\[(left|center|right)\](.*?)\[/\1\]

Replacement:
<div style="text-align: $1;">$2</div>
It doesn't seem to be working =/
Oops, there was an additional '\'.

Try again with the ones on my first post. Working for me.
Thanks! Seems to be working.

Though it seems I can't stack them, like
[right][center]should be center[/center][/right]
Which outputs exactly this:

[center]should be center[/center]

Now you might be wondering why the heck would someone want to stack two alignment BBCodes. Well, it isn't something we want, but it does happen often. For example, someone's post is centered. So the whole post is inside [center] tags. BUT! This guy wants the title to be left aligned. So I will put [left] tags around the title. The [left] tags take priority since they are deeper than the [center] tags.

Can this be fixed? Since these are regular expressions I'm not sure...
In that case, the code will need to be migrated to a plugin, because there's an additional line of code that need's to be applied to the replacement.

I'll adapt the code to a plugin, however can't at this same moment, probably somebody else can do it, but I don't have time.

Be back in about 3 hours.
Regular Expression:
\[(.*?)\](.*?)\[/(.*?)\]

Replacement:
<div align="$1">$2</div>
Try this: