XML and HTML tags

Hi! :wave:

I’m encountering some issue with encoding between XML and HTML while working on my RSS preview page.

I use HTML tags in the title field of some articles (mostly to indicate the language of an English word in a French title). For example: Une fonctionnalité <span lang="en">awesome</>. This is working great on my website. The html tags are interpreted. (BTW this is a feature that I really like about Kirby fields.)

But by default, the feed (Luce Carević — Notes) will show the html tags instead of interpreting them. I guess because of XML encoding.

I’ve found a way to remove the html tags (with Str::unhtml()) but I would rather that the HTML code be interpreted. I’ve tried with no luck to tinker with every escaping/parsing option but this is too complicated for me. The html tags are either deleted (which is at least something) or present in the text instead of interpreted.

I don’t know if I’m exposing my problem very clearly. If it isn’t, I’ll add example of the files.

That should actually be possible with a CDATA tag, like in item part of the snippet: kirby3-feed/rss.php at 95975879e51b29cd8575e84f4d479a61aa0900aa · bnomei/kirby3-feed · GitHub, guess that should work for the title as well, not sure.

I’ve tried but no luck.

I think I’ll let it go. I wanted to provide the proper pronunciation and hide decorative emoji for screenreader users but I cannot control how this will be interpreted in feed readers anyway. So I’ll just strip the html tags and that will be enough.

Thank you anyway. I’m discovering a whole new world with xml!

I could imagine that this is a follow-up problem of the solution discussed in this thread.

With 'mime' => 'xml' you are ending in a Content-Type header of text/xml, but I still think you should have application/xml. Unfortunately, as @sebastiangreger points out, you are bound using the mime options Kirby recognizes but there is no such option to produce application/xml.

However, you could try with 'mime' => 'xhtml' which will result in Content-Type application/xhtml+xml and I think this could work for you.

1 Like

'mime' => 'xhtml' is not working. The preview is not showing at all.

I decided to let go and just strip the tags. It’s not that important.

Thank you!

Don’t give up. At least when I use your feed together with my feedreader plugin, I got this:

Which is not too bad (but the format of your pubdate is not correct). :wink:

Oh that’s weird for the pubdate, it’s working fine in the preview page. It’s also correct on Inoreader. I’ll try the feed on several other feedreaders!

I will let the topic pending for a few days and if I can’t find a solution, I’ll close it :slight_smile:

That’ right. As long as it is taken literally as it is in the pubdate field, it is ok. But in this format it is not parsable and thus one cannot work with it (sorting, translating).

OK, I see why the pubdate is not correct.

I’ve changed the initial content because I wanted to have a nice looking format but that broke the pubdate :see_no_evil:

So, I’ve fixed my pubdate while also having a nice looking format in the XSL file.

For this I simply worked with a custom tag in the XML file where I stored the output format that I needed. I’ve tried before to convert date directly in the XSL file but with no success. Not neat but it works.

<pubDate><?= $datefield === 'modified' ? $item->modified('r', 'date') : date('r', $item->{$datefield}()->toTimestamp()) ?></pubDate>
<joliDate><?= $item->{$datefield}()->toDate('%A %d %B %Y') ?></joliDate>

As for the XML/HTML question.
Looking a bit more into XSL. I’ve found that I could use disable-output-escaping=“yes” on the xsl tag but this is not working in Firefox (98168 - (doe) <xsl:text disable-output-escaping="yes"> not working).

So for now the choices are: to strip the HTML tags or to let them on Firefox. I chose the first option because I think that from a user perspective it’s worse to have the HTML tags than to have an improper pronunciation and occasional emojis.

As I still have a lot to do on my website, I’ll close the topic and let this issue pending for when I have time.

Thank you very much for your inputs. I’ve learn a lot about XSL and RSS feed!

Me too, thanks for sharing your explorations!

I guess not many people will be able to benefit from the blog post I’ve written to sum everything up but here it is: Kirby : mettre en place un flux RSS | Luce Carević

I might do a shorter English version but that would require me to set up the English version of my website (my guess is that this will lead me back here very soon).