Skip to content

feat: strip HTML comments from RSS feed descriptions - #421

Open
manuzhang wants to merge 2 commits into
Guts:mainfrom
manuzhang:feature/strip-html-comments
Open

manuzhang wants to merge 2 commits into
Guts:mainfrom
manuzhang:feature/strip-html-comments

Conversation

@manuzhang

Copy link
Copy Markdown

Add automatic HTML comment removal from all feed item descriptions to ensure clean content in RSS and JSON feeds. Comments are stripped from all content sources including markdown, page.meta descriptions, and full page content.

  • Add strip_html_comments() static method to Util class
  • Update get_description_or_abstract() to strip comments in all code paths
  • Handle both inline and multiline HTML comments
  • Preserve content structure while removing comment artifacts

This prevents HTML comments (including TODO notes, analytics codes, and other internal annotations) from appearing in published feeds.

@github-actions github-actions Bot added the enhancement New feature or request label Jan 22, 2026
@sonarqubecloud

Copy link
Copy Markdown

@manuzhang

Copy link
Copy Markdown
Author

@Guts Please help review, thanks!

@Guts Guts left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Pfiou huge delay here, sorry!

Thanks for the PR, stripping internal comments from feed descriptions is a useful feature. The regex approach works for the simple cases, but there are two edge cases in the truncation branch (chars_count > 0), because the markdown is cut before rendering and the comments are only stripped afterwards.

1. Comment leaks when truncation falls inside it. An unclosed <!-- is escaped by Python-Markdown to &lt;!--, so the regex no longer matches:

md = "Début. <!-- note interne très longue qui sera coupée -->\n\nFin."
# chars_count=25 -> '<p>Début. &lt;!-- note inter...</p>'

The internal note ends up in the feed, which is what this PR aims to prevent.

2. Comments eat the character length. With an 80-character comment at the top of a page and chars_count=50, the output is only &lt;!-- xxxx... and contains no visible text.

Both would be fixed by stripping comments from in_page.markdown before computing lengths and cutting. Please make sure the excerpt delimiter (<!-- more --> by default) is still located first. Comments inside fenced code blocks would then be stripped too, so that case should be handled or documented.

Other points:

  • tests are missing
  • strip_html_comments() is called in six places. Computing the result in the branches and stripping once would be more concise. The regex could also be compiled once at module level.

Can you also rebase please?

manuzhang and others added 2 commits November 2, 2026 20:44
Add automatic HTML comment removal from all feed item descriptions to
ensure clean content in RSS and JSON feeds. Comments are stripped from
all content sources including markdown, page.meta descriptions, and
full page content.

- Add strip_html_comments() static method to Util class
- Update get_description_or_abstract() to strip comments in all code paths
- Handle both inline and multiline HTML comments
- Preserve content structure while removing comment artifacts

This prevents HTML comments (including TODO notes, analytics codes,
and other internal annotations) from appearing in published feeds.

Co-Authored-By: Claude <<EMAIL_ADDRESS>>
Locate excerpt delimiters before removing comments, then measure and truncate the cleaned Markdown. Consolidate final description cleanup and compile the comment pattern once. Add regressions and document comment examples in code blocks.

Co-authored-by: Codex <[email protected]>
@manuzhang
manuzhang force-pushed the feature/strip-html-comments branch from a4b21c1 to aabb23c Compare November 2, 2026 13:58
@github-actions github-actions Bot added documentation Improvements or additions to documentation quality Tests, project resiliency, etc. labels Nov 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 2, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.34%. Comparing base (8e06121) to head (aabb23c).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
+ Coverage   83.58%   84.34%   +0.75%     
==========================================
  Files          11       11              
  Lines         786      792       +6     
  Branches      133      132       -1     
==========================================
+ Hits          657      668      +11     
+ Misses         84       81       -3     
+ Partials       45       43       -2     
Flag Coverage Δ
unittests 84.34% <100.00%> (+0.75%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
mkdocs_rss_plugin/util.py 77.58% <100.00%> (+2.30%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request quality Tests, project resiliency, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants