getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.51k stars 1.4k forks source link

Split function suddenly stopped working #3758

Closed shankar2k closed 11 months ago

shankar2k commented 11 months ago

I use Grav for my company's website, and I implemented a two-column page based on solution listed in general recipes. Today I noticed, that this page is no longer rendering correctly, even though I didn't change anything.

The content of the page looks like this:

### **How to Contact My Company** {.text-center}
###### **My Company** consists of two subcompanies:

---

Stuff about Subcompany #1

- Subcompany #1 bullet one
- Subcompany #1 bullet two

---

Stuff about Subcompany #2

- Subcompany #2 bullet one
- Subcompany #2 bullet two

The template for this page is:

{% extends 'partials/base.html.twig' %}

{% block content %}
    {% set columns = page.content|split('<hr />') %}
    {{ columns[0] }}
    <div class="row justify-content-around">
        <div class="col-md-5">
            {{ columns[1] }}
        </div>
        <div class="col-md-5">
            {{ columns[2] }}
        </div>
    </div>
{% endblock %}

The page is rendered as if the split function does nothing, so that all of the page content remains in columns[0], and then two empty divs rendered below it.

Was a recent change to Grav that caused this split function to stop working? Is there some kind of workaround to get it render as two columns without using the split function?

shankar2k commented 11 months ago

It appears the reason the split wasn't doing anything is that the markdown --- is now rendered in HTML as <hr> rather than <hr />. Is there a way to make the split work for any valid HR tag?

pamtbaau commented 11 months ago

Is there a way to make the split work for any valid HR tag?

I'm afraid not. Filter |split is provided by Twig and according to the Twig docs, only a string can be used as separator.

Also note:

shankar2k commented 11 months ago

I am ambivalent to using or not using the the slash in the <hr> tag. I only included it because my template was based on the recipe for rendering content in columns. Since the rendering of the markdown --- has now been changed to <hr>, I suggest that the recipe be updated to reflect this.

pamtbaau commented 11 months ago

@shankar2k,

You said:

It appears the reason the split wasn't doing anything is that the markdown --- is now rendered in HTML as <hr> rather than <hr />.

I took that remark for granted, but when testing --- in the latest version of Grav, it is still being parsed into <hr />.

It does look like <hr> when inspecting the code in the browser's console, but when looking at the generated HTML source, it shows <hr />.

I also tested your Markdown and Twig snippet and it works as expected. I noticed you are probably using Markdown Extra. Also using Markdown Extra it works as expected.

That you're not using filter |raw when outputting the columns is probably a typo.

shankar2k commented 11 months ago

I am using Grav v1.7.43, and have Markdown Extra enabled. In my template, changing '<hr />' to '<hr>' fixes the problem. In my system I also have External Links v1.6.3, Shortcode Core v5.1.3, and Page Toc v3.2.2 installed, among many of the usual plugins. Could one of these be causing my Grav system to work differently?

pamtbaau commented 11 months ago

Could one of these be causing my Grav system to work differently?

That could well be. They all have an effect on the generated HTML in some way. Try enabling/disabling them one by one and run $ bin/grav cache.

shankar2k commented 11 months ago

Solved. It turns out the Page Toc plugin causes --- to be rendered in HTML at <hr>. Maybe I should raise an issue in that repository.

pamtbaau commented 11 months ago

Maybe I should raise an issue in that repository.

Might be a good idea indeed.