diff --git a/pages/src/main.rs b/pages/src/main.rs index 16454ee..c640204 100644 --- a/pages/src/main.rs +++ b/pages/src/main.rs @@ -1,6 +1,6 @@ use web_sys::{HtmlInputElement, window, InputEvent, HtmlTextAreaElement, wasm_bindgen::JsCast}; use yew::{html, Html, Callback, function_component, TargetCast}; -use rustrict::{Censor, censor_and_analyze_pii}; +use rustrict::{censor_and_analyze_pii, Censor, WordBreak}; #[function_component(App)] fn app() -> Html { @@ -18,8 +18,9 @@ fn app() -> Html { let (censored, analysis) = censor.censor_and_analyze(); let count = censor.total_matches(); let detections = censor.detections(); - let width = rustrict::width_str(&uncensored); - let result = format!("{analysis:?} (width={width}, count={count}, detections={detections:?}, pii={pii:?})"); + let width = rustrict::width_str(&uncensored); + let max_unbroken = rustrict::width_str_max_unbroken(&uncensored, WordBreak::BreakAll); + let result = format!("{analysis:?} (width={width}, max-unbroken={max_unbroken}, count={count}, detections={detections:?}, pii={pii:?})"); analysis_element.set_inner_html(&result); censored_element.set_value(&censored); } diff --git a/src/lib.rs b/src/lib.rs index 81b0eac..7912f5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ pub use replacements::Replacements; pub use trie::Trie; #[cfg(feature = "width")] -pub use width::{trim_to_width, width, width_str, width_str_max_unbroken}; +pub use width::{trim_to_width, width, width_str, width_str_max_unbroken, WordBreak}; #[cfg(feature = "censor")] pub use typ::Type; diff --git a/src/width.rs b/src/width.rs index e50ffee..a80d262 100644 --- a/src/width.rs +++ b/src/width.rs @@ -73,6 +73,7 @@ pub fn width_str(s: &str) -> usize { #[non_exhaustive] pub enum WordBreak { // TODO: BreakWord + /// Same as CSS's `word-break: break-all;`. BreakAll, }