Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mkdocs_rss_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# ##################################

# standard library
import html as html_module
import json
from copy import deepcopy
from dataclasses import asdict
Expand Down Expand Up @@ -357,7 +358,8 @@ def on_page_content(
),
guid=page.canonical_url,
link=page_url_full,
title=page.title,
# MkDocs keeps HTML entities in titles extracted from the H1
title=html_module.unescape(page.title) if page.title else None,
Comment thread
Zerthick marked this conversation as resolved.
Resolved
updated=page_dates[1],
# for later fetch
_mkdocs_page_ref=MkdocsPageSubset.from_page(page),
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/docs/page_with_special_chars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
authors:
- Test Author
date: 2024-01-15 10:00
description: "Description with & ampersand and <angle> brackets"
---

# Test: A & B < C > D

This page tests that special characters are properly encoded in the RSS feed.
The title is derived from the H1, which is the only case where MkDocs
returns it with HTML entities.
4 changes: 4 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,10 @@ def test_xml_escaping_in_author(self):
self.assertIn("OpenSavvy &amp; contributors", feed_xml)
self.assertNotIn("OpenSavvy & contributors</managingEditor>", feed_xml)

# H1-derived titles arrive from MkDocs with HTML entities:
# they must be unescaped once, then escaped once for the XML
self.assertIn("Test: A &amp; B &lt; C &gt; D", feed_xml)


# ##############################################################################
# ##### Stand alone program ########
Expand Down
Loading