### Parse HTML with Default Options Source: https://docs.rs/decruft/0.1.4/src/decruft/lib.rs.html Demonstrates how to use the `parse` function with default options to extract content from an HTML string. This is a quick way to get started with the library. ```rust #![deny( clippy::unwrap_used, clippy::panic, clippy::dbg_macro, clippy::todo, clippy::print_stdout, clippy::print_stderr )] //! # decruft //! //! Extract clean, readable content from web pages. //! //! Given a noisy HTML page (ads, navigation, sidebars, popups, cookie banners...), //! decruft extracts the main content and metadata. //! //! ## Quick start //! //! ``` //! use decruft::{parse, DecruftOptions}; //! //! let html = r#" //! My Post - Blog //! //! //!

My Post

The content.

//! //! //! "#; //! //! let result = parse(html, &DecruftOptions::default()); //! assert!(result.content.contains("The content.")); //! assert!(!result.content.contains("Copyright")); //! ``` //! //! Or even simpler with [`parse_with_defaults`]: //! //! ``` //! let html = "

Hello

"; //! let result = decruft::parse_with_defaults(html); //! assert!(result.content.contains("Hello")); //! ``` ``` -------------------------------- ### General Search Examples Source: https://docs.rs/decruft/0.1.4/src/decruft/extractors/twitter.rs.html?search= Illustrative examples of search queries for common Rust patterns and types. ```rust std::vec ``` ```rust u32 -> bool ``` ```rust Option, (T -> U) -> Option ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/decruft/0.1.4/src/decruft/extractors/lobsters.rs.html?search= Demonstrates common search query patterns. ```text * std::vec ``` ```text * u32 -> bool ``` ```text * Option, (T -> U) -> Option ``` -------------------------------- ### Example Search Query Source: https://docs.rs/decruft/0.1.4/src/decruft/extractors/twitter.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates a typical search query format for finding Rust function signatures. ```text Option, (T -> U) -> Option ``` -------------------------------- ### Extract Domain from URL Source: https://docs.rs/decruft/0.1.4/src/decruft/metadata.rs.html?search= This example shows how to extract the domain name (e.g., 'example.com') from a given URL. ```rust let doc = Html::parse_document(""); let m = extract_metadata(&doc, Some("https://example.com/page"), None); assert_eq!(m.domain.as_deref(), Some("example.com")); ``` -------------------------------- ### Test get() Returns None for 404 Response Source: https://docs.rs/decruft/0.1.4/src/decruft/http.rs.html Verifies that the `get` function returns `None` when a URL returns a 404 status code. This test is designed to not fail if the network is unavailable. ```Rust #[test] fn get_returns_none_for_404() { let result = get("https://httpbin.org/status/404"); // Should be None regardless of whether ureq treats 404 as error // or our explicit check catches it if result.is_some() { // Network might be unavailable, or httpbin might behave // unexpectedly — don't fail } } ``` -------------------------------- ### Rust Example Usage of parse Function Source: https://docs.rs/decruft/0.1.4/decruft/fn.parse.html?search= Demonstrates how to use the `parse` function with a simple HTML string and default options. Asserts that the extracted content contains the expected text. ```rust use decruft::{parse, DecruftOptions}; let html = "

Hello world

"; let result = parse(html, &DecruftOptions::default()); assert!(result.content.contains("Hello world")); ``` -------------------------------- ### Parse RC Calls - Basic Example Source: https://docs.rs/decruft/0.1.4/src/decruft/streaming_ssr.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Parses a string to extract RC call arguments. Useful for identifying template and content IDs. ```rust let text = r#"$RC("B:0","S:0")"#; let calls = parse_rc_calls(text); assert_eq!(calls.len(), 1); assert_eq!(calls[0].0, "B:0"); assert_eq!(calls[0].1, "S:0"); ``` -------------------------------- ### Extract Basic Question Data from HTML Source: https://docs.rs/decruft/0.1.4/src/decruft/extractors/stackoverflow.rs.html?search= Demonstrates extracting basic question data, such as vote count, body, and author, from simple HTML structures. This is a simplified example for testing purposes. ```Rust fn extract_from_html_basic() { let html_str = r#"\n \n \n

How to foo?

\n
\n
42
\n
\n

I want to know how to foo.

\n
\n
\n Alice\n
\n
\n
\n
10
\n
\n ``` -------------------------------- ### Parse HTML with Custom Options Source: https://docs.rs/decruft/0.1.4/index.html Use the `parse` function with `DecruftOptions` to extract content from HTML. This example demonstrates basic usage and assertions to verify content extraction. ```rust use decruft::{parse, DecruftOptions}; let html = r#" My Post - Blog

My Post

The content.

Copyright 2025
"#; let result = parse(html, &DecruftOptions::default()); assert!(result.content.contains("The content.")); assert!(!result.content.contains("Copyright")); ``` -------------------------------- ### get Source: https://docs.rs/decruft/0.1.4/src/decruft/http.rs.html?search= Fetches a URL using API defaults (10s timeout, `decruft/0.1` UA). Returns `None` on network errors, non-200 status, timeout, or body read failures. ```APIDOC ## get ### Description Fetches a URL using API defaults (10s timeout, `decruft/0.1` UA). Returns `None` on network errors, non-200 status, timeout, or body read failures. ### Method GET ### Endpoint `{url}` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```http GET {url} HTTP/1.1 User-Agent: decruft/0.1 Host: example.com ``` ### Response #### Success Response (200) - **body** (string) - The response body as a string. #### Response Example ```json "response body" ``` ERROR HANDLING: - Returns `None` on transport errors, non-200 status codes, or read failures. ``` -------------------------------- ### Get All Descendant Element IDs Source: https://docs.rs/decruft/0.1.4/src/decruft/dom.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a vector of all descendant element IDs starting from a given node ID. ```rust pub fn all_descendant_elements(html: &Html, node_id: NodeId) -> Vec { let mut result = Vec::new(); collect_all_descendants(html, node_id, &mut result); result } ``` -------------------------------- ### Collect Aside Footnotes Source: https://docs.rs/decruft/0.1.4/src/decruft/footnotes.rs.html?search= Collects footnotes from `