11ty / eleventy-plugin-rss

A pack of Eleventy plugins for generating an RSS feed.
https://www.11ty.dev/docs/plugins/rss/
MIT License
92 stars 23 forks source link

Error: PCDATA invalid Char value #5

Closed barcia closed 2 years ago

barcia commented 5 years ago

I got this fail in the .xml, but the config is good. The same config works with other collections, but with posts fails.

This is the error:

This page contains the following errors:
error on line 154 at column 135: PCDATA invalid Char value 24
Below is a rendering of the page up to the first error.
zachleat commented 5 years ago

What xml is this? As far as I know, we don't use xml in Eleventy nor parse it for data

barcia commented 5 years ago

Sorry, I am not explain right … I generate a feed.xml from feed.njk (as is showed in the sample). With my content, the resulting feed.xml does not show up well in the browser. Show the error commented above.

In barcia.dev/feed.xml you can see the error.

From what I have seen, this is caused by the content. In this StackOverflow thread speak about it.

If I can solve it, I put it here.

barcia commented 5 years ago

I finally solved my problem.

I am doing it adding a filter to my content.

  1. Put the filter in .eleventy.js:

    eleventyConfig.addFilter("utf8_xml", (inputStr) => {
    return inputStr.replace(/[^\x09\x0A\x0D\x20-\xFF\x85\xA0-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm, '');
    });
  2. Then, in the feed template, add the filter to the content:

    <content type="html">{{ article.templateContent | htmlToAbsoluteUrls(absoluteArticleUrl) | utf8_xml }}</content>

The solution was founded in StackOverflow

zachleat commented 3 years ago

Finally going through old issues in this repo, can you provide the content that caused this issue to fail? I’d like to add some test cases.

zachleat commented 2 years ago

Closing