Author

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

legendary
Activity: 2982
Merit: 1506
Pie Baking Contest: https://tinyurl.com/2s3z6dee
I'm glad you like it! I only really had you (and other signature designers) in mind when I thought up the [r] tag, so there's not much point in waiting for more feedback; I'll put the tag through one last round of testing and then make a proper patch and post about it soon. (Obviously, there's no telling if theymos will like/merge it, but fingers crossed, yeah?) Grin
It's really getting my attention because for me personally, that tag would be very useful for signature design, more than any other bbcode-things. It's been years for us signature designers, to find the most effective ways to create an attractive signature design in limited space. I think these tags would be the best tools we have and thanks to you, for bringing them! And yeah, fingers crossed Cheesy


P.S. I'm sure I'm not telling you anything that you wouldn't have figured out on your own, but in terms of output size, it'll be more efficient to write your example as: [color=red][r=20]█[/r][/color] (i.e. move the [color] tag outside of the [r] tag).
Thank you for the suggestion PowerGlove! Honestly I didn't think about that before, but you are right man. That way is just more efficient and makes the code easier to read if you want to edit a whole signature design. It's important to manage the code properly so you can keep the characters amount as minimum as possible and make it readable which you wouldn't waste much time to just find the error codes.


It's not wrong if jayce calls you a BBCode master and an icopress table master.
It sounds like I am praising you too much but in fact it is true.

Never mind BBCode's ability, even when I make tables, I still often make mistakes that require corrections so that every explanation written in table format can be seen clearly.
What I convey is just what I experienced on a topic that I made.

Sorry for having the courage to join in on this great discussion.
I am proud of all of your abilities.
No need to sorry man, every opinion matters here Smiley


hero member
Activity: 510
Merit: 4005
Does that work for characters in ascii art too? Like if we want to create long bar in red color, let's say from 20 blocks, instead of [color=red]████████████████████[/color], it means we can just write [r=20][color=red]█[/color][/r]?
Yep, that's exactly right. Smiley

If so, that's cool! It will save plenty spaces and could solve some major issues especially in signature design.
I'm glad you like it! I only really had you (and other signature designers) in mind when I thought up the [r] tag, so there's not much point in waiting for more feedback; I'll put the tag through one last round of testing and then make a proper patch and post about it soon. (Obviously, there's no telling if theymos will like/merge it, but fingers crossed, yeah?) Grin

P.S. I'm sure I'm not telling you anything that you wouldn't have figured out on your own, but in terms of output size, it'll be more efficient to write your example as: [color=red][r=20]█[/r][/color] (i.e. move the [color] tag outside of the [r] tag).



[...]
Hehe, thanks for the kind words. (And thanks for voting for me in the 2022 BCA.) Wink
hero member
Activity: 1540
Merit: 772
It's not wrong if jayce calls you a BBCode master and an icopress table master.
It sounds like I am praising you too much but in fact it is true.

Never mind BBCode's ability, even when I make tables, I still often make mistakes that require corrections so that every explanation written in table format can be seen clearly.
What I convey is just what I experienced on a topic that I made.

Sorry for having the courage to join in on this great discussion.
I am proud of all of your abilities.
legendary
Activity: 2982
Merit: 1506
Pie Baking Contest: https://tinyurl.com/2s3z6dee
[...] challenge is [nbsp] takes more characters than normal space, which the room for styling would be decreased if there are plenty spaces to be filled with the tag. [...]
Hey, jayce! Nice to see you here. Wink

The snip above has crossed my mind too, and one solution I came up with was to add a new [r] tag that "repeats" things. So, if you wanted (let's say) 5 non-breaking spaces, then instead of writing [nbsp][nbsp][nbsp][nbsp][nbsp] you would just write [r=5][nbsp][/r].

I can imagine a tag like that also being useful for other things that come up in signature design (like long sequences of the same character).

What do you think? Would a tag like that be useful to you?

Heyo PowerGlove!

That's actually perfectly well! Does that work for characters in ascii art too? Like if we want to create long bar in red color, let's say from 20 blocks, instead of [color=red]████████████████████[/color], it means we can just write [r=20][color=red]█[/color][/r]? If so, that's cool! It will save plenty spaces and could solve some major issues especially in signature design.
hero member
Activity: 510
Merit: 4005
you would just write [r=5][nbsp][/r].

I can imagine a tag like that also being useful for other things that come up in signature design (like long sequences of the same character).
I don't think this will ever be implemented: the 4000-character limit in signatures is meant to limit the page size. If theymos wanted to increase that, increasing the limit would be much easier.
Yup, I guess. The [r] tag might find uses beyond signature design, though.

I've got the tag working on my branch, and while it did take quite a lot of experimenting to find a way to shoehorn it into the existing parser design, the resulting patch is small and tidy.

There's a conservative size limit on the output it produces, so I don't think it'll cause new problems.

If there's interest, I'll bug theymos with it, otherwise, I'll file it under "Meh." Smiley
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
you would just write [r=5][nbsp][/r].

I can imagine a tag like that also being useful for other things that come up in signature design (like long sequences of the same character).
I don't think this will ever be implemented: the 4000-character limit in signatures is meant to limit the page size. If theymos wanted to increase that, increasing the limit would be much easier.
hero member
Activity: 510
Merit: 4005
[...] challenge is [nbsp] takes more characters than normal space, which the room for styling would be decreased if there are plenty spaces to be filled with the tag. [...]
Hey, jayce! Nice to see you here. Wink

The snip above has crossed my mind too, and one solution I came up with was to add a new [r] tag that "repeats" things. So, if you wanted (let's say) 5 non-breaking spaces, then instead of writing [nbsp][nbsp][nbsp][nbsp][nbsp] you would just write [r=5][nbsp][/r].

I can imagine a tag like that also being useful for other things that come up in signature design (like long sequences of the same character).

What do you think? Would a tag like that be useful to you?
legendary
Activity: 2982
Merit: 1506
Pie Baking Contest: https://tinyurl.com/2s3z6dee
This tag is very useful especially for signature design, which it maintains the design's look on various browsers and devices. This tag also is simpler and shorter comparing to using transparent dot ([color=transparent].[/color]) as a conventional way to replace space. I have applied it in signature design for Coinslotty Contest which the tag really works on both of desktop and mobile screens, but unfortunately I didn't win. Now I'm trying to apply it in my current and next works, but the main challenge is [nbsp] takes more characters than normal space, which the room for styling would be decreased if there are plenty spaces to be filled with the tag. However it's a helpful and the most efficient tag if you prefer mobile-friendly signature design.

PS. PowerGlove also introduced me the [nobbc] tag for the first time. He is a BBCode Master! Since we have icopress as a Table Master already, then there are two masters in this forum!
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
I went spelunking in the SMF source code a while back and found a pretty neat one that I've been using more than I thought I would: [nobbc].
I don't think I've ever used it, but this could come in handy:
Code:
[nobbc]8)[/nobbc]
doesn't work, you will still get the (not) Cool smiley in your message.
👉 Cool

But if you add one space after the closing parenthesis (not before the 8) it will be ok :
Code:
[nobbc]8) [/nobbc]
👉 8)
hero member
Activity: 510
Merit: 4005
There are more hidden BBCodes, and even though I've read the post before, I forgot about the time-tag and possibility to use other BBCode in quote-titles.
I went spelunking in the SMF source code a while back and found a pretty neat one that I've been using more than I thought I would: [nobbc].

It's useful when you want to write about a tag without actually applying it. For example: [b]bold[/b] -> bold.

Code:
[nobbc][b]bold[/b][/nobbc] -> [b]bold[/b]

The nbsp will come in handy some day, especially when dealing with tables.
Yup, it's definitely handy for neatening up tables, but after chatting with jayce about it, I think [nbsp] is likely to start showing up in signatures, too.

A lot of signatures break apart in an uncoordinated way when they don't have enough horizontal space, like this:







This problem shows up when reading posts with a browser window that's too small, and also when viewing profiles:



One remedy is to "glue" the various pieces together so that they can't break apart. This can be accomplished with a workaround ([color=transparent].[/color]), but [nbsp] is both much shorter (which may allow for a more elaborate design to fit within the signature size limit) and more reliable (some characters cause trouble for the workaround, but not for [nbsp]).

legendary
Activity: 1722
Merit: 4711
**In BTC since 2013**
I see only one problem: who's going to know about this? There are more hidden BBCodes, and even though I've read the post before, I forgot about the time-tag and possibility to use other BBCode in quote-titles. And I only remember 1 of the 5 additional smileys
The nbsp will come in handy some day, especially when dealing with tables.

Thank you for drawing attention to this post. Another very useful information for some projects.

So, you make me have to send one more merit...  Roll Eyes
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
How did I not notice this suggestion before!?
It was really an excellent suggestion, and it will be useful for some jobs I'm planning.
I see only one problem: who's going to know about this? There are more hidden BBCodes, and even though I've read the post before, I forgot about the time-tag and possibility to use other BBCode in quote-titles. And I only remember 1 of the 5 additional smileys
The nbsp will come in handy some day, especially when dealing with tables.

I would merit your post, but I've hit the 30-day limit with you after the FlappyCAPTCHA™ thing, so I'll circle back to it later.
Theymos could only send you 1 Merit, also because of the Flappy thing Cheesy What do you know, rules apply to Admin!
hero member
Activity: 510
Merit: 4005
Added, thanks!


Hehe, I was starting to worry that I might never get another patch accepted. Cheesy

Thanks for accepting this one and for letting me contribute to the forum in my own small way, theymos; it means a lot to me!

I would merit your post, but I've hit the 30-day limit with you after the FlappyCAPTCHA™ thing, so I'll circle back to it later. Thanks again. Wink
legendary
Activity: 1722
Merit: 4711
**In BTC since 2013**
How did I not notice this suggestion before!?
It was really an excellent suggestion, and it will be useful for some jobs I'm planning.

Added, thanks!

Thanks @theymos for adding this tag.


Now testing if it works.
Code:
Now[nbsp]testing[nbsp]if[nbsp]it[nbsp]works.
administrator
Activity: 5222
Merit: 13032
Added, thanks!

The only sensible counterargument I can think of is: "Why not just copy/paste U+00A0, when you need a non-breaking space?".

That was my thinking originally. But because SMF automatically translates multiple spaces (like    this) into an alternating sequence of regular spaces and non-breaking spaces in the preparsing step, any intentional usage of non-breaking space characters tends to get messed up, as you mentioned. So when SMF's automatic preparsing-level usage of non-breaking spaces doesn't do what you want, this new tag will be useful.
hero member
Activity: 510
Merit: 4005
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: 784
Merit: 710
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
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: 510
Merit: 4005
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: 510
Merit: 4005
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