Jump to the post that solved this thread.
Solved: 7 Months, 5 Days ago Disable nl2br for a MyCode
Solved: 7 Months, 5 Days ago

I'm running a roleplay forum and the nl2br feature in parsing creates problems when the users want to use HTML templates for their threads.
The coders are from the Jcink platform, where a MyCode "dohtml" exists; when this "dohtml" code is used, new lines are NOT converted to <br>. Jcink isn't open source, so I don't know how they managed to do this but I know that in MyBB, class_parser.php is the file regulating this behavior.

Similarly, I want to use a MyCode and when the user adds this around their code, no new lines will be converted to br. Simply put, I want to reverse the nl2br procedure only for this MyCode.

I thought about replacing all br codes inside a MyCode but that would also remove necessary "br" line breaks put there by the user.

Is there any workaround for this?

At the top of the class_parser file, there's a list of options but I couldn't find any of them on Admin CP:

options = array(

This is the nl2br part in the class_parser file:

if(!isset($this->options['nl2br']) || $this->options['nl2br'] != 0)
			$message = nl2br($message);
			// Fix up new lines and block level elements
			$message = preg_replace("#(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)\s*<br />#i", "$1", $message);
			$message = preg_replace("#(&nbsp;)+(</?(?:html|head|body|div|p|form|table|thead|tbody|tfoot|tr|td|th|ul|ol|li|div|p|blockquote|cite|hr)[^>]*>)#i", "$2", $message);

Could we do something like, if $message contains "dohtml" then nl2br isn't applied?

Solved: 7 Months, 5 Days ago
I've created a little plugin for you that hopefully achieves your aim. It ensures that any text enclosed in [nobr][/nobr] tags does not have newlines replaced with <br>s. Please see the attached file - simply add to your inc/plugins directory and then activate as usual.

Attached Files
.php   addnobrtag.php (Size: 1.74 KB / Downloads: 24)
Solved: 7 Months, 5 Days ago
Wow, thank you so much!

I've just installed it and tested it. Works perfectly!!!

I know that a lot of forums might need this functionality as it's such a pain to try to use the HTML templates we get from "roleplay help" forums. They're made for Jcink and they don't work well on MyBB due to its security-related limitations.

With this plugin, it works like magic Smile

You could easily market this plugin as an alternative to "dohtml" on Jcink.
Of course, people also need to edit the "style/script" blocking code line from the class_parser file.

Thanks again!
Solved: 7 Months, 5 Days ago
You're welcome! I've just updated it though 'cos there was a little bug in it: it wasn't stripping the [nobr] opening and [/nobr] closing tags from the final output. Please download the new version - simply as the (updated) attachment of my previous post.
Jump to the post that solved this thread.

Forum Jump:

Users browsing this thread: 1 Guest(s)