| Crates.io | gitbook2text |
| lib.rs | gitbook2text |
| version | 0.3.1 |
| created_at | 2025-11-10 14:04:04.55213+00 |
| updated_at | 2025-11-12 09:50:51.229552+00 |
| description | A CLI tool to download GitBook pages and convert them to markdown and text |
| homepage | https://github.com/Maki-Grz/gitbook2text |
| repository | https://github.com/Maki-Grz/gitbook2text |
| max_upload_size | |
| id | 1925572 |
| size | 107,520 |
A CLI tool and a Rust library for crawling GitBook sites, downloading their pages, and converting them to Markdown and plain text.
clapcargo install gitbook2text
Add this to your Cargo.toml:
[dependencies]
gitbook2text = "0.3"
Crawls and downloads all pages in a single command:
gitbook2text all https://docs.example.com
Generates the links.txt file with all found links:
gitbook2text crawl https://docs.example.com
# With a custom output file
gitbook2text crawl https://docs.example.com -o my-links.txt
Downloads pages from an existing links file:
gitbook2text download
# With a custom file
gitbook2text download -i my-links.txt
Without a subcommand, downloads from links.txt:
gitbook2text
Files are saved in:
data/md/ - Original markdown filesdata/txt/ - Cleaned text filesuse gitbook2text::{is_gitbook, extract_gitbook_links, crawl_and_save};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://docs.example.com";
// Check if it's a GitBook
if is_gitbook(url).await? {
println!("It's a GitBook!");
// Extract all links
let links = extract_gitbook_links(url).await?;
println!("Found {} pages", links.len());
// Or directly save to a file
crawl_and_save(url, "links.txt").await?;
}
Ok(())
}
use gitbook2text::{download_page, markdown_to_text, txt_sanitize};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://docs.example.com/page.md";
// Download the page
let content = download_page(url).await?;
// Convert to text
let text = markdown_to_text(&content);
// Clean the text
let cleaned = txt_sanitize(&text);
println!("{}", cleaned);
Ok(())
}
# All in one
gitbook2text all https://docs.mydomain.com
# Or step by step
gitbook2text crawl https://docs.mydomain.com
gitbook2text download
#!/bin/bash
# backup-docs.sh
GITBOOK_URL="https://docs.example.com"
BACKUP_DIR="backups/$(date +%Y-%m-%d)"
mkdir -p "$BACKUP_DIR"
cd "$BACKUP_DIR"
gitbook2text all "$GITBOOK_URL"
echo "Backup completed in $BACKUP_DIR"
For the full API documentation, visit docs.rs/gitbook2text.
Contributions are welcome! Feel free to open an issue or a pull request.
See CHANGELOG.md for the version history.
This project is dual-licensed under MIT or Apache-2.0, your choice.