Info Section with text via query seems to escape inline-HTML in markdown

I have an info section that queries its text from another field from the page:

    sections:
      maininfo:
        type: info
        label: Beschreibung
        text: "{{ page.maintext }}"

In the resulting info field in the panel markdown is nicely converted, but all inline-HTML elements are shown as text, so apparently they are escaped in some way.

For example, the following markdown-line:

**›** = <kbd>Alt</kbd>+<kbd>0155</kbd> (PC)

becomes

<strong>›</strong> = &lt;kbd&gt;Alt&lt;/kbd&gt;+&lt;kbd&gt;0155&lt;/kbd&gt; (PC)

however if I include the same line directly in the blueprint, instead of using the query:

text: **›** = <kbd>Alt</kbd>+<kbd>0155</kbd> (PC)

the info field correctly includes:

<strong>›</strong> = <kbd>Alt</kbd>+<kbd>0155</kbd> (PC)

How can I achieve the same with the query?

Hm, that’s a good question. Guess there is some sort of double-escaping happening.

One option would be to overwrite the field itself in a custom field and change the computed text property from toSafeString() to simply using toString().

Another option would be to overwrite the toSafeString() method in a page model for this particular page type.

There are probably other options as well, not sure.

Thanks @texnixe, will look into your suggestions. I guess I was hoping for an easier solution, but well :).

Shouldn’t

text: "{< page.maintext >}"

work in this context?


:warning: Just be aware that this enables anyone with write access to inject arbitrary html into the panel page (javascript included). You have to trust the people with panel write access.

Totally forgot about this syntax :see_no_evil:

Wow, perfect, many thanks! Is this documented anywhere? Injection should be no problem since this is read only content meant for backend documentation. \o/

It is, actually: Query language | Kirby CMS

1 Like

Thanks again! This is making my life so much easier :smiley: