WAIT: Transforming new lines in php to <br>

Browser: Chrome 132.0.2957
OS: Windows
URL: Link to a page that illustrates this issue

I am using LuckyWP Table of Contents as a table of contents plugin.
Somehow in Bricks, there are too many line breaks in the HTML code. For example:

It should however look like this and does also in other themes and page builders:
image

I went through the plugin and I think I found the issue.
The file luckywp-table-of-contents/front/views/items.php seems to be the issue. The file looks like this:

<?php
/**
 * @var $items array
 * @var $depth int
 * @var $containerTag string
 * @var $itemTag string
 */

use luckywp\tableOfContents\core\helpers\Html;

echo Html::beginTag($containerTag, ['class' => 'lwptoc_itemWrap']);
foreach ($items as $item) {
    echo Html::beginTag($itemTag, ['class' => 'lwptoc_item']);
    ?>
    <a href="#<?php echo $item['id'] ?>"<?php echo $item['relNofollow'] ?>>
        <?php if ($item['number']) { ?>
            <span class="lwptoc_item_number"><?php echo $item['number'] . $item['numberSuffix'] ?></span>
        <?php } ?>
        <span class="lwptoc_item_label"><?php echo esc_html($item['label']) ?></span>
    </a>
    <?php
    lwptoc_items($item['childrens']);
    echo Html::endTag($itemTag);
}
echo Html::endTag($containerTag);

And somehow the new lines in line 15 to 20 are translated to <br> when rendering the HTML.
When I remove the new lines in the file as shown here, it works, no additional <br> are created:

<?php
/**
 * @var $items array
 * @var $depth int
 * @var $containerTag string
 * @var $itemTag string
 */

use luckywp\tableOfContents\core\helpers\Html;

echo Html::beginTag($containerTag, ['class' => 'lwptoc_itemWrap']);
foreach ($items as $item) {
    echo Html::beginTag($itemTag, ['class' => 'lwptoc_item']);
    ?>
    <a href="#<?php echo $item['id'] ?>"<?php echo $item['relNofollow'] ?>><?php
        if ($item['number']) { 
            ?><span class="lwptoc_item_number"><?php echo $item['number'] . $item['numberSuffix'] ?> </span><?php
        } ?><span class="lwptoc_item_label"><?php echo esc_html($item['label']) ?></span>
    </a>
    <?php
    lwptoc_items($item['childrens']);
    echo Html::endTag($itemTag);
}
echo Html::endTag($containerTag);

As this error only seems to appear in Bricks, I’m not sure if there is a setting that I have to change.
I already looked, but I didn’t see anything.

I would be happy for any help.

Thank you and best regards

Hello @denzel,

I’ve checked the website you linked, but I don’t see those additional <br /> tags (new lines). Below is a screenshot how it looks on my end.

I guess you fixed it already?

Best regards,
Matej

Hello @Matej ,

sorry, the “correct” version was still cached.
I purged the cache, now you see the current/wrong version.

Thank you for helping and best regards

Hello,

thank you. I can see the issue, you can change it back :slight_smile:

When you have PHP tags (<?php ?>) with HTML in between, any whitespace (including newlines) between them gets rendered as-is in the output HTML.

I’m only curious now, as you said that this is only happening in Bricks. How do you output this code?

Matej

Hey @Matej ,

thank you for the feedback.
So the issue is that in general the html including new line will be rendered.

That’s actually a good question. I’m just a user, so I don’t fully understand how it works.
While looking how to fix the result, I’ve seen that there is an “integration” folder. In there it seems it has kind of configuration file for many page builders. There is a BeaverBuilder.php, Oxygen.php, a whole folder for Elementor, etc.
So it might be, that these integration files take care of that.

For example here the Oxygen.php file. But as I said, I don’t understand what it’s doing:

<?php

namespace luckywp\tableOfContents\integrations;

use luckywp\tableOfContents\core\base\BaseObject;
use luckywp\tableOfContents\core\Core;

class Oxygen extends BaseObject
{

    public function init()
    {
        add_action('ct_builder_start', function () {
            Core::$plugin->onTheContentTrue('');
        }, 1);
        add_action('ct_builder_start', function () {
            global $template_content;
            $template_content = Core::$plugin->shortcode->theContent($template_content);
            Core::$plugin->onTheContentFalse('');
        }, 9999);
    }
}

Do you think it would make sense to add an integration for Bricks?
Otherwise I can post the same question in the LuckyWP forum, it seems to be more of an issue of the plugin than Bricks.

Hey.
It might be, yes. You can try activating the Twenty Twenty-Five or similar default theme, and you will see how it works there.

But is this a shortcode, or how you use this plugin? Sorry, I never used it or heard of it, that’s why I’m asking.

Matej

Hey @Matej ,

it’s a table of contents plugin. So at the beginning of an article it will show the table of contents that is created by the used h-tags.

I tried it with Twenty Twenty-Five and actually it’s displayed correctly there:
image

I also started a post in the LuckWP forum. It seems like Bricks is really the cause:
Looks like Bricks Builder replace new lines to **<br>** . LuckyWP ToC don’t add this tags.

Can you take a look into this? For me it really seems to be a bug in Bricksbuilder as Twenty Twenty-Five and my old Theme could display it correctly and also LuckyWP says they don’t change the HTML.

Thank you and best regards

Hey. I see.

Does this happen on all posts? Because I tested this plugin locally now, and I can’t reproduce the issue.
Can you check that you don’t have any unclosed tags on your page, or maybe if you disable all templates, expect the ones that are absolutely needed?