Skip to main content

extract_article_text

Function extract_article_text 

Source
pub fn extract_article_text(html: &str, base_url: &str) -> Result<String>
Expand description

What: Extract readable text from a bounded HTML news article.

Inputs:

  • html: Article HTML, limited to MAX_ARTICLE_HTML_BYTES bytes.
  • base_url: Absolute HTTP(S) article URL used to resolve relative links.

Output:

  • Plain text with paragraphs, list items, code blocks, and Markdown-safe HTTP(S) links, or an explicit validation/size error.

Details:

  • Script, style, template, and noscript content is discarded rather than interpreted. HTML is never executed.
  • Relative links are resolved against base_url; non-HTTP(S) links remain readable text without a destination.
  • This intentionally small extractor is not a general browser or HTML sanitizer. It preserves the article structures needed by news callers while enforcing input and output bounds.

ยงErrors

Returns ArchToolkitError::InputTooLong when the input or output exceeds its bound, and ArchToolkitError::InvalidInput for an invalid base URL.