Skip to main content

parse_bytes

Function parse_bytes 

Source
pub fn parse_bytes(input: &[u8]) -> Result<Document, HtmlError>
Expand description

Parse raw bytes into a Document, auto-detecting the encoding.

The encoding detection pipeline:

  1. BOM detection (UTF-8, UTF-16 LE/BE)
  2. <meta charset="..."> prescan (first 1 KB)
  3. <meta http-equiv="Content-Type" content="...charset=..."> prescan
  4. Fallback to UTF-8

§Errors

Returns HtmlError::InputTooLarge if the input exceeds 256 MiB, or HtmlError::Encoding if the detected encoding cannot decode the input.

§Example

use fhp_tree::parse_bytes;

let doc = parse_bytes(b"<div>Hello</div>").unwrap();
let root = doc.root();
assert_eq!(root.text_content(), "Hello");