Lines of
src/utils.rs
from check-in 0f47e23e21
that are changed by the sequence of edits moving toward
check-in c996f5c871:
1: use crate::Cursor;
2:
3: use lazy_static::lazy_static;
4: use regex::Regex;
5: use scraper::Html;
6: use stacked_errors::{
7: bail,
8: Result,
9: };
10:
11: lazy_static! {
12: pub static ref RE_SPECIAL: Regex = Regex::new(r"([\-_*\[\]()~`>#+|{}\.!])").unwrap();
13: pub static ref RE_DOMAIN: Regex = Regex::new(r"^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$").unwrap();
14: }
15:
16: /// `Attachment` object to store number attachment data and corresponding file name
17: #[derive(Debug)]
18: pub struct Attachment {
19: pub data: Cursor<Vec<u8>>,
20: pub name: String,
21: }
22:
23: /// Pass any text here to be validated as HTML, breaks on validation errors
24: pub fn validate (text: &str) -> Result<&str> {
25: let fragment = Html::parse_fragment(text);
26: if !fragment.errors.is_empty() {
27: bail!(fragment.errors.join("\n"));
0f47e23e21 2026-01-12 28: } else {
0f47e23e21 2026-01-12 29: Ok(text)
30: }
31: }