Expand description
§gitbook2text
A library and CLI tool to download GitBook pages and convert them into markdown and plain text.
§Exemples
§Crawling a GitBook
use gitbook2text::{is_gitbook, extract_gitbook_links};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://docs.example.com";
if is_gitbook(url).await? {
let links = extract_gitbook_links(url).await?;
println!("Trouvé {} pages", links.len());
}
Ok(())
}§Download and conversion
use gitbook2text::{download_page, markdown_to_text, txt_sanitize};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://example.com/page.md";
let content = download_page(url).await?;
let text = markdown_to_text(&content);
let cleaned = txt_sanitize(&text);
println!("{}", cleaned);
Ok(())
}Enums§
Functions§
- crawl_
and_ save - Extracts links from a GitBook and saves them to a file
- download_
page - Download the content of a page from a URL
- extract_
gitbook_ links - Extracts all documentation links from a GitBook site
- is_
gitbook - Checks if a URL points to a GitBook site
- markdown_
to_ text - Converts markdown to plain text
- save_
markdown - Save the markdown content to a file
- save_
text - Saves the text content to a file
- txt_
sanitize - Cleans and sanitizes the text by removing special GitBook tags
- url_
to_ filename - Converts a URL into a safe filename