Skip to content

fix: WikipediaConverter renders hash None heading when page has no title#1990

Open
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-1968-wikipedia-converter-none-heading
Open

fix: WikipediaConverter renders hash None heading when page has no title#1990
hanhan761 wants to merge 1 commit into
microsoft:mainfrom
hanhan761:fix-1968-wikipedia-converter-none-heading

Conversation

@hanhan761
Copy link
Copy Markdown

Fixes #1968

Problem

When WikipediaConverter processes a page without a <title> element (or with an empty title), the f-string on line 78 renders # None as the document heading because main_title is None and Python f-strings render None as the string "None".

Fix

Changed the f-string on line 78 to use a conditional expression that only includes the heading when main_title is truthy:

webpage_text = (f"# {main_title}\n\n" if main_title else "") + ...

Test

Added test_wikipedia_converter_no_title which creates an HTML page without a title element and verifies that # None does not appear in the output.

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.

bug: WikipediaConverter renders hash None heading when page has no title

1 participant