Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rendering content to CDATA section #102

Open
MFAshby opened this issue Dec 21, 2024 · 0 comments
Open

Allow rendering content to CDATA section #102

MFAshby opened this issue Dec 21, 2024 · 0 comments

Comments

@MFAshby
Copy link
Contributor

MFAshby commented Dec 21, 2024

Related a bit to #101

Use case: I want to generate an RSS feed with the full content of my posts embedded in the RSS XML file. Here is my superhtml template:

<rss version="2.0" 
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Home on mfashby.net</title>
    <link>https://mfashby.net/</link>
    <description>Recent content in Home on mfashby.net</description>
    <language>en-gb</language>
    <lastBuildDate>Sun, 03 Mar 2024 19:31:27 +0000</lastBuildDate>
    <atom:link href="https://mfashby.net/index.xml" rel="self" type="application/rss+xml"/>
    <item :loop="$page.subpages()">
      <title :text="$loop.it.title"></title>
      <link :text="$loop.it.link()"></link>
      <pubDate :text="$loop.it.date.formatHTTP()"></pubDate>
      <guid isPermaLink="true" :text="$loop.it.link()"></guid>
      <description :text="$loop.it.description"></description>
      <content:encoded :html="$loop.it.content()"></content:encoded> 
    </item>
  </channel>
</rss>

however, valid HTML is not necessarily valid XML; so in order for the rendered RSS file to remain valid XML it might be necessary to escape the content HTML. The easiest way to achieve this might be to render the element content into a CDATA section. See https://www.rssboard.org/rss-profile#namespace-elements-content-encoded, but I did not find a way to do this in Zine/SuperHTML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant