microsoft / microsoft/markitdown
HTML: <title> leaks into markdown body for documents without <body>; stray content outside <body> dropped
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 186k
- Forks
- 13.7k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 49
Description
Description
HtmlConverter converts only the <body> element when present, and the whole document otherwise. Since BeautifulSoup's html.parser does not synthesize or relocate elements the way a browser does:
- a valid HTML5 document without
<body>tags leaks its<title>text into the markdown body - any content placed before/after
<body>is silently dropped
Reproduction
from io import BytesIO
from markitdown import MarkItDown, StreamInfo
html = b'<html><head><title>Page Title</title></head><p>hello</p></html>'
MarkItDown().convert_stream(BytesIO(html), stream_info=StreamInfo(extension='.html')).markdown
# 'Page Title\n\nhello' <-- title leaks into the body
html2 = b'before<body><p>in body</p></body>after'
# 'before' and 'after' are dropped entirely
Expected behavior
Head metadata stays out of the markdown (except when used as the doc title), and stray content outside <body> is preserved, matching what a browser considers rendered content.
Environment
markitdown main (cc0ca9e), Python 3.12
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the HtmlConverter entry point and reproduce both examples from the issue with MarkItDown.convert_stream. Verify that head metadata is excluded from the markdown body while content outside an explicit body is preserved, and add regression coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100