Skip to content

fix(rss): treat Atom text content and summary as plain text - #2374

Merged
Adam Fourney (afourney) merged 6 commits into
microsoft:mainfrom
lazerg:fix/issue-2373-atom-plain-text
Sep 3, 2026
Merged

Adam Fourney (afourney) merged 6 commits into
microsoft:mainfrom
lazerg:fix/issue-2373-atom-plain-text

Conversation

@lazerg

Copy link
Copy Markdown
Contributor

Atom content and summary with type="text" (or no type at all) are plain text, but the converter hands them to the HTML parser anyway. Anything tag-shaped in that text gets dropped and entity-like strings get decoded a second time, so Run <job_id> with &lt;literal&gt;. comes out as Run with <literal>.

_get_atom_content now escapes those two cases before the existing HTML path runs, which keeps the literal text intact while html and xhtml content converts as before.

Fixes #2373

@afourney

Copy link
Copy Markdown
Member

Ishaan Potle (@IshaanPotle) I think this is tackling the same issue as #2375. I've been working in this one. Can you confirm if it addresses your issue?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Plain text remains active Markdown, and multiline normalization can discard meaningful indentation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes Atom plain-text content handling while retaining HTML/XHTML conversion behavior.

Changes:

  • Classifies Atom content types and skips binary payloads.
  • Adds plain-text rendering and whitespace normalization.
  • Adds regression tests across Atom content variants.
File summaries
File Description
_rss_converter.py Implements Atom content classification and rendering.
test_rss_converter.py Covers text, HTML, XML, binary, and whitespace cases.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +215 to +217
lines = text.splitlines()
if len(lines) > 1:
text = lines[0] + "\n" + textwrap.dedent("\n".join(lines[1:]))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, reproduced with a two-line value that starts on the content element's own line. Dedenting the full text now, in d272b88. Added a test for it.

Comment on lines +224 to +227
if not is_markup:
# Plain text is returned verbatim: routing it through the HTML
# parser drops tag-shaped text such as ``<job_id>`` entirely.
return value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed with bold, link, and a leading #. Fixed in d272b88 by escaping asterisks, brackets, and line-leading # in the plain-text value before it's returned, so it stays literal instead of turning into Markdown. Added a regression test.

@IshaanPotle

Copy link
Copy Markdown

Adam Fourney (@afourney) Yes — confirming #2374 addresses the same issue as my #2375. Lazizbek Ergashev (@lazerg) opened this one first (17:32 vs my 17:38), and I didn't see it when I checked for duplicates. Happy to close mine in favour of this.

This PR is also the more thorough of the two on classification: the media-type handling (text/html, +xml, base64 binary), the text-construct vs atom:content distinction, and the dedent so indented feed text doesn't read as a code block are all things mine doesn't do.

One gap worth flagging before this merges, though — the Copilot reviewer raised the same point on #2375. Returning plain text verbatim fixes the Markdown source but not what a reader ends up seeing, because the text is still live Markdown/HTML. Checked out this branch and ran the issue's own example:

markdown source : Run <job_id> with &lt;literal&gt;.     ← identifier is back ✅
renders back to : Run  with <literal>.                   ← identifier gone again ❌
original text   : Run <job_id> with &lt;literal&gt;.

(rendered with the markdown package, tags stripped.) Any consumer that renders the output still loses <job_id>, and separately *literal* in plain text becomes emphasis.

On #2375 I ended up escaping the value instead — convert it as a text node so the converter applies its own Markdown escaping, then escape the markup characters markdownify leaves alone. That round-trips exactly:

markdown source : Run &lt;job\_id&gt; with &amp;lt;literal&amp;gt;.
renders back to : Run <job_id> with &lt;literal&gt;.     ✅

Verified that ordinary prose isn't over-escaped (well-known, 1. are untouched). Commit is here if it's useful — genuinely happy for Lazizbek Ergashev (@lazerg) to take the escaping bit into this PR, or I can send it as a follow-up once this lands. Whichever is less work for you.

@IshaanPotle

Copy link
Copy Markdown

Re-tested at d272b88 — the Markdown metacharacter escaping works:

in    : Use *literal* and [label](url).
source: Use \\*literal\\* and \\[label\\](url).
renders: Use *literal* and [label](url).   ✅

The angle-bracket case from the issue title is still open though, since <, > and & aren't in the escape set:

in     : Run <job_id> with &lt;literal&gt;.
source : Run <job_id> with &lt;literal&gt;.
renders: Run  with <literal>.               ❌ identifier still dropped

<job_id> is read as an HTML tag at render time and &lt; decodes to <, so the original symptom survives for any consumer that renders the Markdown. html.escape(value, quote=False) applied after the Markdown escaping covers it:

source : Run &amp;lt;job\\_id&amp;gt; with &amp;amp;lt;literal&amp;amp;gt;.
renders: Run <job_id> with &lt;literal&gt;.  ✅

Worth noting it makes the source noisier than the literal example in #2373 — that example wasn't escaped and would lose <job_id> again when rendered, so I read "with appropriate Markdown escaping" as pointing here, but that's a judgement call for Adam Fourney (@afourney).

Nothing else from me — the classification work in this PR is better than what I had, and the dedent fix is a case I missed entirely. Happy to close #2375 whenever you'd like.

@afourney
Adam Fourney (afourney) force-pushed the fix/issue-2373-atom-plain-text branch from d272b88 to a98483c Compare September 3, 2026 21:57
@lazerg

Copy link
Copy Markdown
Contributor Author

Checked this against the current tip. The angle-bracket drop is real when you render the markdown to HTML: <job_id> gets read as a tag and &lt;literal&gt; decodes to <literal>, same as you found.

Your html.escape fix works on its own. But it clashes with what this issue actually asked for. The issue's own repro expects result.markdown to end with the literal string Run <job_id> with &lt;literal&gt;., unescaped. This branch already produces that (I ran the #2373 repro directly, it passes). Adding html.escape changes that source to Run &lt;job_id&gt; with &amp;lt;literal&amp;gt;., which breaks 5 existing tests (test_atom_plain_text_content_is_not_parsed_as_html, test_atom_untyped_summary_is_not_parsed_as_html, test_atom_text_media_type_content_is_not_parsed_as_html, test_atom_summary_media_type_is_treated_as_text, test_atom_plain_text_layout_whitespace_is_removed). I applied it locally, confirmed the failures, then reverted.

So there are two different, both defensible, targets: keep the markdown source byte-identical to the plain-text input (current behavior, matches the issue's stated expected output), or make the markdown safe to re-render as HTML (your fix, at the cost of a noisier source). That is a real product decision, not a bug in either of our patches. Adam Fourney (@afourney), your call on which one this repo wants.

@afourney

Copy link
Copy Markdown
Member

Lazizbek Ergashev (@lazerg) please have your agent stop responding, and stop adding commits to the PR.

@afourney
Adam Fourney (afourney) merged commit 697a2a0 into microsoft:main Sep 3, 2026
5 checks passed
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

Successfully merging this pull request may close these issues.

Atom plain-text content and summary lose literal angle-bracket text

4 participants