markitdown
markitdown copied to clipboard
Add CSS selector flag to HTML converter
- This PR introduces the -s/--selector flag to the MarkItDown CLI, allowing users to specify a CSS selector to narrow the scope of HTML parsing.
- CLI Update: Added -s/--selector flag to the CLI to allow passing a CSS selector.
- HtmlConverter Modification: The CSS selector is passed through to the HtmlConverter for processing.
- Scoped BeautifulSoup Parsing: When the -s/--selector flag is used, BeautifulSoup parsing is scoped to the elements matching the selector, improving parsing performance and relevance.
- Error Handling: If no matches are found for the provided selector, a ValueError is raised to inform the user about the lack of matching elements.
How to Test:
- Run the CLI with the -s/--selector flag
- python -m markitdown -s 'article.entry' path/to/input.html
All related tests pass:
- pytest -s tests/test_html_selector.py
@microsoft-github-policy-service agree