Skip to main content

trim_trailing_image_path

Function trim_trailing_image_path 

Source
pub fn trim_trailing_image_path<F>(raw: &str, candidate_check: F) -> &str
where F: Fn(&str) -> bool,
Expand description

Trim trailing text from a raw image path match.

When a regex greedily matches an image path that contains spaces, it may also consume trailing prose (e.g., “/path/to/image.png can you see”). This function walks backwards through whitespace-delimited tokens to find the longest prefix that looks like a valid image path.

The candidate_check closure receives a trimmed candidate string and returns true if it should be accepted as a valid image path.