Nesting bbcode in an attribute

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

Nesting bbcode in an attribute

Post by Ger » Tue Sep 05, 2017 9:42 am

-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?
Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

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

User avatar
3Di
Registered User
Posts: 11719
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: Nesting bbcode in an attribute

Post by 3Di » 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.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

User avatar
JoshyPHP
Code Contributor
Posts: 686
Joined: Mon Jul 11, 2011 12:28 am

Re: Nesting bbcode in an attribute

Post by JoshyPHP » Tue Sep 05, 2017 8:22 pm

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 thing that does the BBCodes in 3.2. Unless it broke yours, in which case it was somebody else with a similar name.

User avatar
Ger
Registered User
Posts: 1019
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Nesting bbcode in an attribute

Post by Ger » Wed Sep 06, 2017 7:00 am

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.
Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

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

User avatar
JoshyPHP
Code Contributor
Posts: 686
Joined: Mon Jul 11, 2011 12:28 am

Re: Nesting bbcode in an attribute

Post by JoshyPHP » Wed Sep 06, 2017 1:53 pm

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 thing that does the BBCodes in 3.2. Unless it broke yours, in which case it was somebody else with a similar name.

User avatar
Ger
Registered User
Posts: 1019
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Nesting bbcode in an attribute

Post by Ger » Wed Sep 06, 2017 2:24 pm

I see. Thanks for explaining :)
Checkout my extensions: Simple CMS, Feed post bot, Modbreak, Magic OGP links and Live topic update

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

User avatar
3Di
Registered User
Posts: 11719
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano - Frankfurt
Name: Marco
Contact:

Re: Nesting bbcode in an attribute

Post by 3Di » Wed Sep 06, 2017 10:03 pm

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. :)
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades

Post Reply

Return to “Custom BBCode Development and Requests”

Who is online

Users browsing this forum: No registered users and 7 guests

cron