| Crates.io | markdowndown |
| lib.rs | markdowndown |
| version | 0.1.0 |
| created_at | 2025-09-01 16:29:47.574209+00 |
| updated_at | 2025-09-01 16:29:47.574209+00 |
| description | A Rust library for acquiring markdown from URLs with smart handling |
| homepage | |
| repository | https://github.com/wballard/markdowndown |
| max_upload_size | |
| id | 1819879 |
| size | 1,239,290 |
A Rust library for converting URLs to markdown with intelligent handling of different URL types.
cargo add markdowndown
use markdowndown::convert_url;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let markdown = convert_url("https://example.com/article").await?;
println!("{}", markdown);
Ok(())
}
use markdowndown::{MarkdownDown, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::builder()
.github_token("ghp_your_token_here")
.timeout_seconds(60)
.user_agent("my-app/1.0")
.build();
let md = MarkdownDown::with_config(config);
let result = md.convert_url("https://github.com/rust-lang/rust/issues/1").await?;
println!("{}", result);
Ok(())
}
| URL Type | Example | Features |
|---|---|---|
| HTML Pages | https://example.com/article |
Clean HTML to markdown conversion |
| Google Docs | https://docs.google.com/document/d/{id}/edit |
Direct markdown export |
| Office 365 | https://company.sharepoint.com/.../document.docx |
Document download and conversion |
| GitHub Issues | https://github.com/owner/repo/issues/123 |
Issue + comments via API |
convert_url(url) - Convert any URL to markdown with default configurationconvert_url_with_config(url, config) - Convert with custom configurationdetect_url_type(url) - Determine URL type without conversionMarkdownDown - Main library struct with configurationConfig - Configuration builder for customizing behaviorMarkdown - Validated markdown content wrapperMarkdownError - Comprehensive error handlinglet config = Config::builder()
// Authentication
.github_token("ghp_xxxxxxxxxxxxxxxxxxxx")
.office365_token("office_token")
.google_api_key("google_key")
// HTTP Settings
.timeout_seconds(60)
.user_agent("MyApp/1.0")
.max_retries(5)
// Output Options
.include_frontmatter(true)
.custom_frontmatter_field("project", "my-project")
.max_consecutive_blank_lines(2)
.build();
The library provides comprehensive error handling with specific error types:
use markdowndown::{convert_url, types::MarkdownError};
match convert_url("https://example.com").await {
Ok(markdown) => println!("Success: {}", markdown),
Err(MarkdownError::ValidationError { kind, context }) => {
eprintln!("Invalid input: {:?}", kind);
}
Err(MarkdownError::EnhancedNetworkError { kind, context }) => {
eprintln!("Network issue: {:?}", kind);
}
Err(MarkdownError::AuthenticationError { kind, context }) => {
eprintln!("Auth problem: {:?}", kind);
}
Err(e) => eprintln!("Other error: {}", e),
}
Typical conversion times on modern hardware:
| URL Type | Small Document | Medium Document | Large Document |
|---|---|---|---|
| HTML Page | < 1s | 1-3s | 3-10s |
| Google Docs | < 2s | 2-5s | 5-15s |
| GitHub Issue | < 1s | 1-2s | 2-5s |
| Office 365 | 2-5s | 5-15s | 15-60s |
Note: Performance metrics are hardware and network dependent. Actual conversion times may vary based on your system specifications, network connectivity, and document complexity.
Memory usage scales linearly with document size. Network latency is typically the limiting factor.
The repository includes comprehensive examples in the examples/ directory:
basic_usage.rs - Simple URL conversionwith_configuration.rs - Custom configuration usagebatch_processing.rs - Converting multiple URLsasync_usage.rs - Async/await patternserror_handling.rs - Comprehensive error handlingRun examples with:
cargo run --example basic_usage
cargo run --example with_configuration
The library can be configured via environment variables:
export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx
export MARKDOWNDOWN_TIMEOUT=60
export MARKDOWNDOWN_USER_AGENT="MyApp/1.0"
export MARKDOWNDOWN_MAX_RETRIES=5
Then use:
let config = Config::from_env();
let md = MarkdownDown::with_config(config);
# Check the project
cargo check
# Build the project
cargo build
# Run tests
cargo test
# Run integration tests
cargo test --test integration_tests
# Generate documentation
cargo doc --open
# Run benchmarks
cargo bench
We welcome contributions! Please see CONTRIBUTING.md for guidelines on:
MIT License - see LICENSE file for details.
See CHANGELOG.md for version history and breaking changes.
examples/ directory