HTML content gets cut off in a Markdown block of a blocks field


I have a Kirby 3.9.0-rc.1 page with a blocks field. When I paste in a relatively long text with HTML tags, the output get’s cut off at a specific point. For outputting the block’s content, I use this: <?= $page->text()->toBlocks() ?>. The blocks field only contains one single block of type Markdown.

I suspect some HTML tag is not recognized or rendered properly and thus the rendering stops at that point. Is there a way to find technical information on what’s wrong? The page returns no error in the frontend and the page saves without any issue. Debugging is active. PHP version is v8.1.

When I use e. g. $page->text() or $page->text()->html() the page content isn’t cut off, just the formatting is wrong.

Thanks for your help.

Best Regards

First thing I‘d try is validate the pasted HTML in a validator

I just did a quick check with The W3C Markup Validation Service and it reports only one error about a meta tag so the error looks quite irrelevant and would have caused issues at other pages too. The HTML code I’m pasting is coming from a third party who generates the input on their side for further consumption by me. So I have no influence on the code nor do I know the code in detail (means I would have to check every single line to find every HTML tag and to see if/what could be wrong). Beside of that, I suspect that there might be some HTML tag unknown, browser-specific or in general too specific/rare so some parsing or validation fails. Is there a way to get more details of what Kirby tries to render? PHP error log only shows other errors, e. g. outdated entries.

Is there maybe an option to enable to output invalid HTML because I don’t care if it’s theoretically broken? Then I know it’s a validation issue somewhere and if my browser complains about the HTML code as well.

Don’t think so. Does it render correctly if you paste it into a standard textarea field and render with kirbytext?

I just found out that when I use a blocks field with a text block (instead of a Markdown block), I can see the output as well so I suspect this is not related to how $page->field()->text() or html() work but rather an issue with the Markdown block of the blocks field. The text I have struggles with is copyright-protected so I can’t share it public. Is there a way I can share this via email or something and someone of the Kirby team takes a look? As this is a legal text, it’s a bit negative that I can’t get it properly published as expected. Of course, if it turns out that the text is wrongly formatted and I didn’t notice that, I have to talk to the author of this document. Happens with newer Kirby v3 version and newer PHP8 version as well.

Any reason why you don’t use a text field then if that works? If you want, you can send me the text and I take a look.

The text has formatting so I would like to keep that for a better user experience. Furthermore the text is provided as-is thus I just want to have one field for copy and paste or for updating a single field with an API call without having to split the text in several blocks and thus make the maintenance more effort. Maybe this isn’t the right approach and I miss something obvious here. I even tried to strip down the HTML text to its basics to find out what is broken but I wasn’t successful. I send you the text, thank you for your support!

Just leaving some info here in case anyone runs into this as well.

The issue came from pasting HTML code into a single Markdown block with Markdown extra enabled.

There are five options to solve this issue:

  • disable Markdown extra if not needed for other purposes otherwise
  • paste the text into multiple blocks
  • wrap everything into a div
  • play around with line formatting until it works :wink:
  • try another Markdown parser

I personally would probably paste the text into multiple blocks, at least that’s what I did with a similar privacy text in one of my projects.

1 Like