Nesting bbcode in an attribute

Get help developing custom BBCodes or request one.
Post Reply
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Nesting bbcode in an attribute

Post by Ger »

-Edit-
I use phpBB 3.2.1, but this subforum is situated under 3.1 support.

Triggered by this topic I went to create a BBcode for rich tooltips. Currently, I have the BBcode like this:

Usage
[note={TEXT1}]{TEXT2}[/note]

HTML replacement

Code: Select all

<div class="infobox-trigger">
    <div class="info-trigger-text">{TEXT1}</div>
    <i class="icon fa-info-circle fa-fw" aria-hidden="true"></i>
    <div class="infobox">{TEXT2}</div>
</div>
Along with this CSS (improvement possible, but not the issue here)

Code: Select all

.infobox-trigger {
    position: relative;
    display: inline-block;
    cursor: pointer;
}
.infobox-trigger .info-trigger-text {
    border-bottom: 1px dashed #999;
    display: inline;
}

.infobox-trigger .icon {
    font-size: 0.8em;
    position: relative;
    top: -3px;
}
.infobox {
    position: absolute;
    z-index: 2;
    background-color: #ffffbe;
    border: 2px solid #ccc;
    width: 20vW;
    max-width: 500px;
    min-width: 100px;
    padding: 5px;
    visibility: hidden;
}
.infobox-trigger:hover .infobox {
    visibility: visible;
}
Now this works nice, it results in something like this:
previewgood.png
However, when I use nested BBcode in the atrribute, it fails:
previewbad.png
I used it here like:

Code: Select all

Lorem ipsum [note=[i]dolor[/i] sit amet]This is plain [b]silly[/b] text[/note],
So I can use nested BBcode in TEXT2, but not in TEXT1? I can't imagine this is intended? I can't find any documentation about this. How can I get this to work?
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Nesting bbcode in an attribute

Post by 3Di »

An extension already exists for such a BBcode:
viewtopic.php?f=456&t=2358036
Which uses javascript, feel free to have a look at it though, since I don't recall about nesting.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: Nesting bbcode in an attribute

Post by JoshyPHP »

Ger wrote: Tue Sep 05, 2017 9:42 am So I can use nested BBcode in TEXT2, but not in TEXT1? I can't imagine this is intended?
This is expected and not something that's likely to change. If you need recursive parsing you need to use nested BBCodes. As a rule of thumb, you can expect the BBCode syntax to work similarly to HTML.
I wrote the library that handles markup in phpBB 3.2+.
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Nesting bbcode in an attribute

Post by Ger »

3Di wrote: Tue Sep 05, 2017 7:38 pm An extension already exists for such a BBcode:
viewtopic.php?f=456&t=2358036
Which uses javascript, feel free to have a look at it though, since I don't recall about nesting.
Hah, thanks, didn't see that earlier. Could have saved me some work. :)
-edit-
I looked into it. The result is pretty much the same, but your (or Primehalo's) approach is way more complicated. I guess that's because my approach uses a bit more modern CSS that wasn't available on most browsers in 2007.
Feel free to uses my code if it suits you.

---
JoshyPHP wrote: Tue Sep 05, 2017 8:22 pm This is expected and not something that's likely to change. If you need recursive parsing you need to use nested BBCodes. As a rule of thumb, you can expect the BBCode syntax to work similarly to HTML.
Well, that's what I would expect. When typing this:

Code: Select all

Lorem ipsum dolor [note=sit [b]amet[/b][/note]This is just [b]silly[/b] text[/note] consecteur
I would expect it to be parsed like

Code: Select all

Lorem ipsum dolor <div class="infobox-trigger">
<div class="info-trigger-text">sit <strong>amet</strong></div>
    <i class="icon fa-info-circle fa-fw" aria-hidden="true"></i>
    <div class="infobox">This is just <strong>silly</strong> text</div>
</div> consecteur
That HTML is fine, just look at the result in this fiddle

However, the textformatter seems to cut off the TEXT1 attribute at the very first ] it sees.
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: Nesting bbcode in an attribute

Post by JoshyPHP »

Ger wrote: Wed Sep 06, 2017 7:00 am I would expect it to be parsed like [...]
I'm saying that as the library's developer; That's the behaviour I expect, e.g. not a bug, a coincidence or a surprise. I don't use the word intended because there's no specific intention to it. I would consider parsing markup inside of attribute values if there was a simple way to do it. There's nothing simple about it however, that's why I don't expect it to ever change.
I wrote the library that handles markup in phpBB 3.2+.
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Nesting bbcode in an attribute

Post by Ger »

I see. Thanks for explaining :)
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Nesting bbcode in an attribute

Post by 3Di »

Ger wrote: Wed Sep 06, 2017 7:00 am -edit-
I looked into it. The result is pretty much the same, but your (or Primehalo's) approach is way more complicated. I guess that's because my approach uses a bit more modern CSS that wasn't available on most browsers in 2007.
Feel free to uses my code if it suits you.
I already use a CSS like yours for other extensions of mine.

With some modification maybe could be used also over there, I will look into it at the due time.
Thanks. :)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
Post Reply

Return to “Custom BBCode Development and Requests”