Author

Topic: Adding [nbsp] (non-breaking space) to the BBCode parser (SMF patch) (Read 165 times)

hero member
Activity: 501
Merit: 3855
While looking through the SMF source code a while back remember seeing some comments like "not sure why the below code is working" or smth like that. It was related either to BBCode parser or search function. To be fair in an older version though, close to the one the forum is using.
Yup, the SMF codebase has a lot of fun/earnest comments. It makes going through the code a lot less of a slog. Cheesy

Here are a few from the BBCode parser:

// Never show smileys for wireless clients.  More bytes, can't see it anyway :P.
// !!! Maybe this can be simplified?
// Shhhh!
// Can't have a one letter smiley, URL, or email! (sorry.)
// !!! Don't think is the real solution....
// This is SADLY and INCREDIBLY browser dependent.
// Are we there yet?  Are we there yet?
// Did we just eat through everything and not find it?
// No tag?  Keep looking, then.  Silly people using brackets without actual tags.

But I guess most software have some parts made by a guy that went AWOL at some point and nobody knew exactly how that code worked so just ran with it as much as they could Tongue (Windows is no exception)
Yeah, that's true. Especially for Windows. Microsoft used to have some seriously talented programmers, and I'm pretty sure that most of their more recent engineering hires are left scratching their heads at some of the code that's still around from the old days.

I'm just poking fun at the SMF team, I kind of get how they arrived at their design for the BBCode parser. It's not what I would have done, and it's very fragile and difficult to change without introducing new problems, but it does work. Grin
copper member
Activity: 763
Merit: 692
Defend Bitcoin and its PoW: bitcoincleanup.com
As a small aside, the BBCode parser is a goddamned mess and I'm not sure what the SMF peeps were smoking when they designed it, but it must have been some seriously next-level stuff.

While looking through the SMF source code a while back remember seeing some comments like "not sure why the below code is working" or smth like that. It was related either to BBCode parser or search function. To be fair in an older version though, close to the one the forum is using.

But I guess most software have some parts made by a guy that went AWOL at some point and nobody knew exactly how that code worked so just ran with it as much as they could Tongue (Windows is no exception)
legendary
Activity: 2212
Merit: 7064
Cashback 15%
So, in summary: I can't think of a good reason not to merge this patch, it seems like a strict improvement to me.
I would agree with you and my suggestion is to try contacting theymos with personal messages and ask his opinion about this patch.
He probably doesn't follow non-stop everything that is happening and maybe he missed this one.
I think I remember you had other patch proposals, so better to send one message for all of them, maybe he picks one that he likes most  Wink
hero member
Activity: 501
Merit: 3855
Bumping this because I feel it deserves a little more attention. It's obviously not the most exciting patch, but it adds something useful to BBCode and it does so in an unobtrusive way; I've never seen theymos' modifications but I'm guessing that when he added the [btc] tag to the forum, he probably went about it in a similar way (minus the custom font). As a small aside, the BBCode parser is a goddamned mess and I'm not sure what the SMF peeps were smoking when they designed it, but it must have been some seriously next-level stuff.

A [nbsp] tag is a genuinely useful thing to have, and I'm surprised that it wasn't defined for BBCode from the start. The only sensible counterargument I can think of is: "Why not just copy/paste U+00A0, when you need a non-breaking space?". Well, beyond the obvious usability improvements ([nbsp] is much easier to see, share and talk about than:  <-- there's a non-breaking space there, in case you missed it), a more subtle reason is that a naked non-breaking space won't survive a post being edited. For example, here's a table that uses non-breaking spaces in a few key spots to keep things tidy:

Strain name
hero member
Activity: 501
Merit: 3855
A non-breaking space is a way to prevent a piece of text from "breaking" into multiple parts when there's not enough room for it to fit comfortably. This can be useful when formatting tables (I first proposed it here: Re: Gangs of BitcoinTalk). It can also be useful for signatures, too (e.g. @Royse777 could have used it recently when improving the ChipMixer signatures, [nbsp] would have worked better than [color=transparent].[/color] and could have allowed the design to remain the same; it wouldn't have been necessary to change the "{" into a "#").

Although using the Unicode character (U+00A0) directly is possible, it's much handier (and more "semantic") to make it available as a BBCode tag.

Here's a small patch for @theymos to add [nbsp] to this version of SMF:

Code:
--- /var/www/baseline/Sources/Subs.php	2011-09-17 21:59:55.000000000 +0000
+++ /var/www/modified/Sources/Subs.php 2023-02-20 02:20:01.000000000 +0000
@@ -1389,40 +1389,45 @@
  'after' => '
',
  'block_level' => true,
  ),
  array(
  'tag' => 'me',
  'type' => 'unparsed_equals',
  'before' => '
* $1 ',
  'after' => '
',
  'quoted' => 'optional',
  'block_level' => true,
  'disabled_before' => '/me ',
  'disabled_after' => '
',
  ),
  array(
  'tag' => 'move',
  'before' => '',
  'after' => '
',
  'block_level' => true,
  ),
+ array(
+ 'tag' => 'nbsp',
+ 'type' => 'closed',
+ 'content' => ' ',
+ ),
  array(
  'tag' => 'nobbc',
  'type' => 'unparsed_content',
  'content' => '$1',
  ),
  array(
  'tag' => 'pre',
  'before' => '
',
  'after' => '
',
  ),
  array(
  'tag' => 'php',
  'type' => 'unparsed_content',
  'content' => '
$1
',
  'validate' => isset($disabled['php']) ? null : create_function('&$tag, &$data, $disabled', '
  if (!isset($disabled[\'php\']))
  {
  $add_begin = substr(trim($data), 0, 5) != \'<?\';
  $data = highlight_php_code($add_begin ? \'<?php \' . $data . \'?>\' : $data);
  if ($add_begin)
  $data = preg_replace(array(\'~^(.+?)<\?.{0,40}?php( |\s)~\', \'~\?>((?:)*)$~\'), \'$1\', $data, 2);
Jump to:
© 2020, Bitcointalksearch.org