Strip all styling markup from a raw string, returning only visible text.
(raw: &str)
| 2329 | |
| 2330 | /// Strip all styling markup from a raw string, returning only visible text. |
| 2331 | pub fn strip_styling(raw: &str) -> String { |
| 2332 | let mut result = String::new(); |
| 2333 | let mut escaped = false; |
| 2334 | let mut in_style_def = false; |
| 2335 | for c in raw.chars() { |
| 2336 | if escaped { |
| 2337 | result.push(c); |
| 2338 | escaped = false; |
| 2339 | continue; |
| 2340 | } |
| 2341 | match c { |
| 2342 | '\\' => { escaped = true; } |
| 2343 | '{' if !in_style_def => { in_style_def = true; } |
| 2344 | '|' if in_style_def => { in_style_def = false; } |
| 2345 | '}' if !in_style_def => { /* closing tag, skip */ } |
| 2346 | _ if in_style_def => { /* inside style def, skip */ } |
| 2347 | _ => { result.push(c); } |
| 2348 | } |
| 2349 | } |
| 2350 | result |
| 2351 | } |
| 2352 | |
| 2353 | /// Convert a "structural visual" position (includes } and empty content markers) |
| 2354 | /// to a "content position" (just visible chars, matching strip_styling output). |
no outgoing calls