From 2055f7082ee58b8e64bfe28834eb32983533149e Mon Sep 17 00:00:00 2001 From: John Morris <2e0byo@gmail.com> Date: Tue, 3 Feb 2026 13:23:23 +0100 Subject: [PATCH] feat: expose Readability creation from `scraper::Html`. As it happens I wanted to use this in a context where I already have an `Html` struct, so this saves re-parsing. --- src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 120dbc4..ea957a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -776,9 +776,8 @@ pub enum LogLevel { } impl Readability { - /// Create a new Readability parser from HTML content - pub fn new(html: &str, options: Option) -> Result { - let document = Html::parse_document(html); + /// Create a new Readability parser from a parsed HTML document + pub fn new_from_document(document: Html, options: Option) -> Result { let options = options.unwrap_or_default(); Ok(Self { @@ -800,6 +799,12 @@ impl Readability { }) } + /// Create a new Readability parser from HTML content + pub fn new(html: &str, options: Option) -> Result { + let document = Html::parse_document(html); + Self::new_from_document(document, options) + } + /// Create a new Readability parser with a base URI for resolving relative URLs pub fn new_with_base_uri(html: &str, base_uri: &str, options: Option) -> Result { let mut parser = Self::new(html, options)?;