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 22 forks source link

htmlToAbsoluteUrls uncloses self-closed tags #12

Closed Aias closed 3 years ago

Aias commented 4 years ago

I'm using Eleventy to generate a blog with an Atom feed, basically an exact clone of https://github.com/11ty/eleventy-base-blog.

As part of .eleventy.js, I have configured markdown to add <br/> tags for line breaks.

let markdownOpts = {
    html: true,
    breaks: true,
    linkify: true
};

I noticed that my feed wasn't working, and if I opened it directly in Chrome, I received an error:

error on line 133 at column 43: Opening and ending tag mismatch: br line 0 and p

Because the breaks in the resulting markup were not self-closing - they were rendered as <br>. So I added xhtmlOut: true to the options above, thinking this would solve the issue, and it does add the closing slashes to breaks in templates, but for some reason I was still missing them in my feed.xml. Finally, I realized that removing the htmlToAbsoluteUrls filter from the <content> tags solved the issue, so somehow it's breaking things.

<content type="html">{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) | safe }}</content>

I'm guessing this has to do with how posthtml is parsing the content. Not quite sure what to do about it, since I think it'd be extremely complicated to get it to match whatever xhtmlOut option I've specified in my markdown options.

revelt commented 3 years ago

A year has passed so I'm probably too late, but I noticed the | safe in the <content> snippet above.

It's opportunistic but can it be the culprit? Zach himself uses without | safe:

https://github.com/zachleat/zachleat.com/blob/d610186da82956e00e1aa0577d5bc13ef1865e98/web/notes/feed/atom.njk#L26

same way like eleventy-base-blog:

https://github.com/11ty/eleventy-base-blog/blob/61885752b698cada7b8c2635fb662c83eed031c7/feed/feed.njk#L26

Please share the RSS template so we can troubleshoot (or if the issue has been solved since, let us know so we can close).

zachleat commented 3 years ago

Escaping the content would likely work but I changed the default postHTML behavior to use XHTML single tags for better compatibility.

Fixes #12. Switches postHTML closingSingleTag to 'slash' to be better with XML output if the content isn’t escaped as `safe` (html entity encoded). Also adds `posthtmlRenderOptions` option to override if needed.