Lines of
src/utils.rs
from check-in 85fa6bddaa
that are changed by the sequence of edits moving toward
check-in bf99298edf:
1: use crate::Cursor;
2:
3: use std::borrow::Cow;
4:
5: use html_escape::encode_text;
6: use lazy_static::lazy_static;
3c858ed7c4 2026-07-31 7: use regex::Regex;
8: use stacked_errors::{
9: bail,
10: Result,
11: };
12:
13: lazy_static! {
85fa6bddaa 2026-01-18 14: 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();
85fa6bddaa 2026-01-18 15: pub static ref RE_CLOSING: Regex = Regex::new(r"</[ \t]*(pre|code)[ \t]*>").unwrap();
16: }
17:
85fa6bddaa 2026-01-18 18: /// `Attachment` object to store number attachment data and corresponding file name
19: #[derive(Debug)]
20: pub struct Attachment {
21: pub data: Cursor<Vec<u8>>,
22: pub name: String,
23: }
24:
25: /// Pass any text here to be validated as not breaking from Telegram preformatted blocks
26: /// escape all HTML chars afterwards
85fa6bddaa 2026-01-18 27: pub fn validate (text: &str) -> Result<Cow<'_, str>> {
28: if RE_CLOSING.is_match(text) {
29: bail!("Telegram closing tag found.");
30: } else {
31: Ok(encode_text(text))
32: }
33: }