Custom BBcodes parsed with xpath doesn't allows markup inside it

Get help developing custom BBCodes or request one.
Post Reply
User avatar
cholo981
Registered User
Posts: 62
Joined: Mon Nov 10, 2014 9:40 am

Custom BBcodes parsed with xpath doesn't allows markup inside it

Post by cholo981 » Thu Mar 30, 2017 5:21 pm

I'm still trying to shape my custom BBCODEs to make them works as much as possible similar to their previous behaviour in 3.1.

With a big help from JoshyPHP I think I got the perfect solution for the [spoiler]/[spoiler=] issue:
JoshyPHP wrote:
Thu Mar 30, 2017 1:16 pm
COLOR doesn't accept empty strings so it works as intended but if you use a token that accepts empty strings you can do something like @ref != ''. You can't use the token itself (e.g. {COLOR}) in XPath expressions though.
But I still have a huge problem to solve and I think it could actually be NOT related to my "personal enviroment":

If I use Xpath in the BBCODE trasformation parser, I can't insert any markup inside it. Which is weird because the TextFormatter should totally allow it and the only issue related to it I found, it's about nesting the same bbcode multiple times.

I made a test to show you the problem as clearly as possible.

To run this test I activated the standard prosilver 3.2 style. phpbb 3.2, the last release (updated from 3.1.9).
I forgot to disable all the extensions too when I was taking the screenshots, but I did it later (including ABBC) and I got the same results.

OLD syntax:

Code: Select all

[spoiler]{TEXT1}[/spoiler]
Transform:

Code: Select all

<span class="spoiler"> {TEXT1}</span>
NEW syntax:

Code: Select all

[spoiler={TEXT1;optional}]{TEXT2}[/spoiler]
Transform:

Code: Select all

<xsl:choose>
	<xsl:when test="@spoiler!=''">
		<div class="spoiler"><small> {TEXT1}</small>{TEXT2}</div>
	</xsl:when>
	<xsl:otherwise>
		<span class="spoiler"> {TEXT2}</span>
	</xsl:otherwise>
</xsl:choose>

INPUT STRING:

Code: Select all

[spoiler]Test [b]BOLD[/b][/spoiler]
Output with the old bbcode syntax: ✅
Image

HTML:

Code: Select all

<span class="spoiler"> Test <span style="font-weight: bold">BOLD</span></span>

Output with the new one: ❌
Image

HTML:

Code: Select all

<span class="spoiler"> Test [b]BOLD[/b]</span>
If you need additional information, feel free to ask or try run it for yourself.

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

Re: Custom BBcodes parsed with xpath doesn't allows markup inside it

Post by JoshyPHP » Thu Mar 30, 2017 7:15 pm

Hrm, that's interesting. I don't see anything wrong with your BBCode and I don't know why it works that way. I can confirm that I see the same issue on my test board.

I'll look into it asap.
I wrote the thing that does BBCodes in 3.2.

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

Re: Custom BBcodes parsed with xpath doesn't allows markup inside it

Post by JoshyPHP » Fri Mar 31, 2017 2:53 am

I looked into it and it's due to mixing <div> and <span>, making it both a block element and an inline element. If you use all divs it'll work better.

If you want both block spoilers and inline spoilers I recommend creating two BBCodes for it, like there are two BBCodes for [c] and [code].

Edit: actually no, that explanation is incorrect. It shouldn't prevent [b] from being used. There might be a bug somewhere. Changing to all divs or all spans does fix it though.
I wrote the thing that does BBCodes in 3.2.

User avatar
cholo981
Registered User
Posts: 62
Joined: Mon Nov 10, 2014 9:40 am

Re: Custom BBcodes parsed with xpath doesn't allows markup inside it

Post by cholo981 » Fri Mar 31, 2017 6:05 am

JoshyPHP wrote:
Fri Mar 31, 2017 2:53 am
I looked into it and it's due to mixing <div> and <span>, making it both a block element and an inline element. If you use all divs it'll work better.

If you want both block spoilers and inline spoilers I recommend creating two BBCodes for it, like there are two BBCodes for [c] and [code].

Edit: actually no, that explanation is incorrect. It shouldn't prevent [b] from being used. There might be a bug somewhere. Changing to all divs or all spans does fix it though.
No big deal then. I made them both span and added a class to the block span to shape it with the css. I think it works way better than create two different bbcode (especially for the past).

Input

Code: Select all

[spoiler]Test [b]bold[/b][/spoiler]after

[spoiler=]Test [b]bold[/b][/spoiler]after

[spoiler=Text title]Test[b]bold[/b] in a box
Test [b]bold[/b] in a box
Test [b]bold[/b] in a box[/spoiler]after
Output

Code: Select all

<span class="spoiler"> Test <strong>bold</strong></span>after<br>
<br>
<span class="spoiler"> Test <strong>bold</strong></span>after<br>
<br>
<span class="boxed spoiler"><small> Text title</small>Test<strong>bold</strong> in a box<br>
Test <strong>bold</strong> in a box<br>
Test <strong>bold</strong> in a box</span>after
Image

Hope the issue can get fixed for the future though, seems kind of unpredictable.
Big thanks for the help.

edit: I mean... if the problem it's related to the first child element in the condition branches, probably surrounding them with a span may be enough. Ugly though.
Last edited by cholo981 on Fri Mar 31, 2017 10:18 am, edited 1 time in total.

User avatar
cholo981
Registered User
Posts: 62
Joined: Mon Nov 10, 2014 9:40 am

Re: Custom BBcodes parsed with xpath doesn't allows markup inside it

Post by cholo981 » Fri Mar 31, 2017 10:17 am

edit: double

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

Re: Custom BBcodes parsed with xpath doesn't allows markup inside it

Post by JoshyPHP » Fri Mar 31, 2017 4:18 pm

cholo981 wrote:
Fri Mar 31, 2017 6:05 am
edit: I mean... if the problem it's related to the first child element in the condition branches, probably surrounding them with a span may be enough. Ugly though.
Yes, I tracked down the issue earlier and it's fixed in GitHub. Wrapping the div in a span would work but it's invalid HTML so it may have other side effects.
I wrote the thing that does BBCodes in 3.2.

Post Reply

Return to “Custom BBCode Development and Requests”