webdown 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- webdown-0.8.0/LICENSE +21 -0
- webdown-0.8.0/PKG-INFO +374 -0
- webdown-0.8.0/README.md +338 -0
- webdown-0.8.0/pyproject.toml +106 -0
- webdown-0.8.0/webdown/__init__.py +141 -0
- webdown-0.8.0/webdown/cli.py +718 -0
- webdown-0.8.0/webdown/config.py +112 -0
- webdown-0.8.0/webdown/converter.py +275 -0
- webdown-0.8.0/webdown/crawler.py +335 -0
- webdown-0.8.0/webdown/error_utils.py +159 -0
- webdown-0.8.0/webdown/html_parser.py +304 -0
- webdown-0.8.0/webdown/link_extractor.py +262 -0
- webdown-0.8.0/webdown/markdown_converter.py +273 -0
- webdown-0.8.0/webdown/output_manager.py +228 -0
- webdown-0.8.0/webdown/tests/__init__.py +1 -0
- webdown-0.8.0/webdown/tests/conftest.py +8 -0
- webdown-0.8.0/webdown/tests/test_claude_xml.py +164 -0
- webdown-0.8.0/webdown/tests/test_cli.py +838 -0
- webdown-0.8.0/webdown/tests/test_config.py +112 -0
- webdown-0.8.0/webdown/tests/test_config_combinations.py +149 -0
- webdown-0.8.0/webdown/tests/test_converter.py +551 -0
- webdown-0.8.0/webdown/tests/test_crawler.py +397 -0
- webdown-0.8.0/webdown/tests/test_error_utils.py +154 -0
- webdown-0.8.0/webdown/tests/test_errors.py +100 -0
- webdown-0.8.0/webdown/tests/test_html_parser.py +291 -0
- webdown-0.8.0/webdown/tests/test_integration.py +142 -0
- webdown-0.8.0/webdown/tests/test_link_extractor.py +296 -0
- webdown-0.8.0/webdown/tests/test_markdown_converter_extended.py +104 -0
- webdown-0.8.0/webdown/tests/test_output_manager.py +245 -0
- webdown-0.8.0/webdown/tests/test_streaming.py +115 -0
- webdown-0.8.0/webdown/tests/test_validation.py +217 -0
- webdown-0.8.0/webdown/tests/test_xml_converter.py +501 -0
- webdown-0.8.0/webdown/tests/test_xml_converter_extended.py +160 -0
- webdown-0.8.0/webdown/validation.py +183 -0
- webdown-0.8.0/webdown/xml_converter.py +283 -0
webdown-0.8.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Travis Cole
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
webdown-0.8.0/PKG-INFO
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webdown
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: Convert web pages and HTML files to markdown and Claude XML formats
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: web,markdown,html,converter,html-to-markdown,claude-xml,web-scraping,content-extraction,anthropic
|
|
8
|
+
Author: Travis Cole
|
|
9
|
+
Author-email: kelp@plek.org
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
24
|
+
Requires-Dist: beautifulsoup4 (>=4.13.3,<5.0.0)
|
|
25
|
+
Requires-Dist: html2text (>=2024.2.26,<2025.0.0)
|
|
26
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
27
|
+
Requires-Dist: tqdm (>=4.67.1,<5.0.0)
|
|
28
|
+
Project-URL: Bug Tracker, https://github.com/kelp/webdown/issues
|
|
29
|
+
Project-URL: Changelog, https://github.com/kelp/webdown/blob/main/CHANGELOG.md
|
|
30
|
+
Project-URL: Documentation, https://tcole.net/webdown/
|
|
31
|
+
Project-URL: Homepage, https://tcole.net/webdown
|
|
32
|
+
Project-URL: Repository, https://github.com/kelp/webdown
|
|
33
|
+
Project-URL: Source Code, https://github.com/kelp/webdown
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# Webdown
|
|
37
|
+
|
|
38
|
+
[](https://github.com/kelp/webdown/actions/workflows/python-tests.yml)
|
|
39
|
+
[](https://codecov.io/gh/kelp/webdown)
|
|
40
|
+
[](https://badge.fury.io/py/webdown)
|
|
41
|
+
[](https://pypi.org/project/webdown/)
|
|
42
|
+
[](https://opensource.org/licenses/MIT)
|
|
43
|
+
|
|
44
|
+
A Python CLI tool for converting web pages to clean, readable Markdown format. Webdown makes it easy
|
|
45
|
+
to download documentation and feed it into an LLM coding tool.
|
|
46
|
+
|
|
47
|
+
## Why Webdown?
|
|
48
|
+
|
|
49
|
+
- **Clean Conversion**: Produces readable Markdown without formatting artifacts
|
|
50
|
+
- **Selective Extraction**: Target specific page sections with CSS selectors
|
|
51
|
+
- **Claude XML Format**: Optimized output format for Anthropic's Claude AI models
|
|
52
|
+
- **Progress Tracking**: Visual download progress for large pages with `-p` flag
|
|
53
|
+
- **Optimized Handling**: Automatic streaming for large pages (>10MB) with no configuration required
|
|
54
|
+
|
|
55
|
+
## Use Cases
|
|
56
|
+
|
|
57
|
+
### Documentation for AI Coding Assistants
|
|
58
|
+
|
|
59
|
+
Webdown is particularly useful for preparing documentation to use with AI-assisted coding tools like Claude Code, GitHub Copilot, or ChatGPT:
|
|
60
|
+
|
|
61
|
+
- Convert technical documentation into clean Markdown for AI context
|
|
62
|
+
- Extract only the relevant parts of large documentation pages using CSS selectors
|
|
63
|
+
- Strip out images and formatting that might consume token context
|
|
64
|
+
- Generate well-structured tables of contents for better navigation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Example: Convert API docs and store for AI coding context
|
|
68
|
+
webdown https://api.example.com/docs -s "main" -I -c -w 80 -o api_context.md
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
### From PyPI
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install webdown
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### With Homebrew
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Add the tap
|
|
83
|
+
brew tap kelp/tools
|
|
84
|
+
|
|
85
|
+
# Install webdown
|
|
86
|
+
brew install webdown
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Install from Source
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Clone the repository
|
|
93
|
+
git clone https://github.com/kelp/webdown.git
|
|
94
|
+
cd webdown
|
|
95
|
+
|
|
96
|
+
# Install with pip
|
|
97
|
+
pip install .
|
|
98
|
+
|
|
99
|
+
# Or install with Poetry
|
|
100
|
+
poetry install
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Usage
|
|
104
|
+
|
|
105
|
+
Basic usage:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
webdown https://example.com/page.html -o output.md
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Output to stdout:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
webdown https://example.com/page.html
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Options
|
|
118
|
+
|
|
119
|
+
- `-o, --output`: Output file (default: stdout)
|
|
120
|
+
- `-t, --toc`: Generate table of contents
|
|
121
|
+
- `-L, --no-links`: Strip hyperlinks
|
|
122
|
+
- `-I, --no-images`: Exclude images
|
|
123
|
+
- `-s, --css SELECTOR`: CSS selector to extract specific content
|
|
124
|
+
- `-c, --compact`: Remove excessive blank lines from the output
|
|
125
|
+
- `-w, --width N`: Set the line width for wrapped text (0 for no wrapping)
|
|
126
|
+
- `-p, --progress`: Show download progress bar (useful for large files)
|
|
127
|
+
- `--claude-xml`: Output in Claude XML format for use with Claude AI
|
|
128
|
+
- `--no-metadata`: Exclude metadata section from Claude XML output (metadata is included by default)
|
|
129
|
+
- `--no-date`: Exclude current date from metadata in Claude XML output (date is included by default)
|
|
130
|
+
|
|
131
|
+
For more details on the Claude XML format, see the [Anthropic documentation on Claude XML](https://docs.anthropic.com/claude/docs/advanced-data-extraction).
|
|
132
|
+
|
|
133
|
+
For large web pages (over 10MB), streaming mode is automatically used to optimize memory usage without any configuration required.
|
|
134
|
+
|
|
135
|
+
## Examples
|
|
136
|
+
|
|
137
|
+
Generate markdown with a table of contents:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
webdown https://example.com -t -o output.md
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Extract only main content:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
webdown https://example.com -s "main" -o output.md
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Strip links and images:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
webdown https://example.com -L -I -o output.md
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Compact output with progress bar and line wrapping:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
webdown https://example.com -c -p -w 80 -o output.md
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Generate Claude XML format for use with Claude AI:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
webdown https://example.com --claude-xml -o doc.xml
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Claude XML with no metadata section:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
webdown https://example.com --claude-xml --no-metadata -o doc.xml
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Claude XML without the current date in metadata:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
webdown https://example.com --claude-xml --no-date -o doc.xml
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
For complete documentation, use the `--help` flag:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
webdown --help
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Documentation
|
|
186
|
+
|
|
187
|
+
API documentation is available online at [tcole.net/webdown](https://tcole.net/webdown/).
|
|
188
|
+
|
|
189
|
+
You can also generate the documentation locally with:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
make docs # Generate HTML docs in the docs/ directory
|
|
193
|
+
make docs-serve # Start a local documentation server at http://localhost:8080
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
### Prerequisites
|
|
199
|
+
|
|
200
|
+
- Python 3.10+ (3.13 recommended)
|
|
201
|
+
- [Poetry](https://python-poetry.org/docs/#installation) for dependency management
|
|
202
|
+
|
|
203
|
+
### Setup
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# Clone the repository
|
|
207
|
+
git clone https://github.com/kelp/webdown.git
|
|
208
|
+
cd webdown
|
|
209
|
+
|
|
210
|
+
# Install dependencies with Poetry
|
|
211
|
+
poetry install
|
|
212
|
+
poetry run pre-commit install
|
|
213
|
+
|
|
214
|
+
# Optional: Start a Poetry shell for interactive development
|
|
215
|
+
poetry shell
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Development Commands
|
|
219
|
+
|
|
220
|
+
We use a Makefile to streamline development tasks:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Install dependencies
|
|
224
|
+
make install
|
|
225
|
+
|
|
226
|
+
# Run tests
|
|
227
|
+
make test
|
|
228
|
+
|
|
229
|
+
# Run tests with coverage
|
|
230
|
+
make test-coverage
|
|
231
|
+
|
|
232
|
+
# Run integration tests
|
|
233
|
+
make integration-test
|
|
234
|
+
|
|
235
|
+
# Run linting
|
|
236
|
+
make lint
|
|
237
|
+
|
|
238
|
+
# Run type checking
|
|
239
|
+
make type-check
|
|
240
|
+
|
|
241
|
+
# Format code
|
|
242
|
+
make format
|
|
243
|
+
|
|
244
|
+
# Run all pre-commit hooks
|
|
245
|
+
make pre-commit
|
|
246
|
+
|
|
247
|
+
# Run all checks (lint, type-check, test)
|
|
248
|
+
make all-checks
|
|
249
|
+
|
|
250
|
+
# Build package
|
|
251
|
+
make build
|
|
252
|
+
|
|
253
|
+
# Start interactive Poetry shell
|
|
254
|
+
make shell
|
|
255
|
+
|
|
256
|
+
# Generate documentation
|
|
257
|
+
make docs
|
|
258
|
+
|
|
259
|
+
# Start documentation server
|
|
260
|
+
make docs-serve
|
|
261
|
+
|
|
262
|
+
# Publishing to PyPI (maintainers only)
|
|
263
|
+
# See CONTRIBUTING.md for details on the release process
|
|
264
|
+
make build # Build package
|
|
265
|
+
make publish-test # Publish to TestPyPI (for testing)
|
|
266
|
+
|
|
267
|
+
# Show all available commands
|
|
268
|
+
make help
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Poetry Commands
|
|
272
|
+
|
|
273
|
+
You can also use Poetry directly:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# Start an interactive shell in the Poetry environment
|
|
277
|
+
poetry shell
|
|
278
|
+
|
|
279
|
+
# Run a command in the Poetry environment
|
|
280
|
+
poetry run pytest
|
|
281
|
+
|
|
282
|
+
# Add a new dependency
|
|
283
|
+
poetry add requests
|
|
284
|
+
|
|
285
|
+
# Add a development dependency
|
|
286
|
+
poetry add --group dev black
|
|
287
|
+
|
|
288
|
+
# Update dependencies
|
|
289
|
+
poetry update
|
|
290
|
+
|
|
291
|
+
# Build package
|
|
292
|
+
poetry build
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Python API Usage
|
|
296
|
+
|
|
297
|
+
Webdown can also be used as a Python library in your own projects:
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
from webdown.converter import convert_url_to_markdown, WebdownConfig
|
|
301
|
+
|
|
302
|
+
# Basic conversion
|
|
303
|
+
markdown = convert_url_to_markdown("https://example.com")
|
|
304
|
+
|
|
305
|
+
# Using the Config object for more options
|
|
306
|
+
config = WebdownConfig(
|
|
307
|
+
url="https://example.com",
|
|
308
|
+
include_toc=True,
|
|
309
|
+
css_selector="main",
|
|
310
|
+
compact_output=True,
|
|
311
|
+
body_width=80,
|
|
312
|
+
show_progress=True
|
|
313
|
+
)
|
|
314
|
+
markdown = convert_url_to_markdown(config)
|
|
315
|
+
|
|
316
|
+
# Save to file
|
|
317
|
+
with open("output.md", "w") as f:
|
|
318
|
+
f.write(markdown)
|
|
319
|
+
|
|
320
|
+
# Convert to Claude XML format (optimized for Anthropic's Claude AI)
|
|
321
|
+
from webdown.converter import convert_url_to_claude_xml, ClaudeXMLConfig
|
|
322
|
+
|
|
323
|
+
# Basic Claude XML conversion
|
|
324
|
+
xml = convert_url_to_claude_xml("https://example.com")
|
|
325
|
+
|
|
326
|
+
# With custom XML configuration
|
|
327
|
+
claude_config = ClaudeXMLConfig(
|
|
328
|
+
include_metadata=True, # Include title, URL, and date (default: True)
|
|
329
|
+
add_date=True, # Include current date in metadata (default: True)
|
|
330
|
+
doc_tag="claude_documentation" # Root document tag name (default)
|
|
331
|
+
)
|
|
332
|
+
xml = convert_url_to_claude_xml("https://example.com", claude_config)
|
|
333
|
+
|
|
334
|
+
# Save XML output
|
|
335
|
+
with open("output.xml", "w") as f:
|
|
336
|
+
f.write(xml)
|
|
337
|
+
|
|
338
|
+
# For more information on Claude XML format, see:
|
|
339
|
+
# https://docs.anthropic.com/claude/docs/advanced-data-extraction
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
## Contributing
|
|
343
|
+
|
|
344
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
345
|
+
|
|
346
|
+
1. Fork the repository
|
|
347
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
348
|
+
3. Run tests to make sure everything works:
|
|
349
|
+
```bash
|
|
350
|
+
# Run standard tests
|
|
351
|
+
poetry run pytest
|
|
352
|
+
|
|
353
|
+
# Run tests with coverage
|
|
354
|
+
poetry run pytest --cov=webdown
|
|
355
|
+
|
|
356
|
+
# Run integration tests
|
|
357
|
+
poetry run pytest --integration
|
|
358
|
+
```
|
|
359
|
+
4. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
360
|
+
5. Push to the branch (`git push origin feature/amazing-feature`)
|
|
361
|
+
6. Open a Pull Request
|
|
362
|
+
|
|
363
|
+
Please make sure your code passes all tests, type checks, and follows our coding style (enforced by pre-commit hooks). We aim to maintain high code coverage (currently at 93%). When adding features, please include tests.
|
|
364
|
+
|
|
365
|
+
For more details, see [our Contributing Guide](https://tcole.net/webdown/contributing/).
|
|
366
|
+
|
|
367
|
+
## Support
|
|
368
|
+
|
|
369
|
+
If you encounter any problems or have feature requests, please [open an issue](https://github.com/kelp/webdown/issues) on GitHub.
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
374
|
+
|