MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / strip_html

Function strip_html

crates/opencode-tool/src/webfetch.rs:279–373  ·  view source on GitHub ↗
(html: &str)

Source from the content-addressed store, hash-verified

277}
278
279fn strip_html(html: &str) -> String {
280 let mut result = String::new();
281 let mut in_tag = false;
282 let mut in_script = false;
283 let mut in_style = false;
284 let chars: Vec<char> = html.chars().collect();
285 let len = chars.len();
286 let mut i = 0;
287
288 while i < len {
289 let c = chars[i];
290
291 if c == '<' {
292 if i + 7 <= len {
293 let tag: String = chars[i..i + 7].iter().collect();
294 let tag_lower = tag.to_lowercase();
295 if tag_lower.starts_with("<script") {
296 in_script = true;
297 } else if tag_lower.starts_with("<style") {
298 in_style = true;
299 }
300 }
301 in_tag = true;
302 i += 1;
303 continue;
304 }
305
306 if c == '>' {
307 if in_script {
308 if i >= 8 {
309 let end_tag: String = chars[i - 8..=i].iter().collect();
310 if end_tag.to_lowercase() == "</script>" {
311 in_script = false;
312 }
313 }
314 } else if in_style {
315 if i >= 7 {
316 let end_tag: String = chars[i - 7..=i].iter().collect();
317 if end_tag.to_lowercase() == "</style>" {
318 in_style = false;
319 }
320 }
321 }
322 in_tag = false;
323 i += 1;
324 continue;
325 }
326
327 if !in_tag && !in_script && !in_style {
328 if c == '&' {
329 if i + 4 <= len {
330 let entity: String = chars[i..i + 4].iter().collect();
331 match entity.as_str() {
332 "&lt;" => {
333 result.push('<');
334 i += 4;
335 continue;
336 }

Callers 1

executeMethod · 0.85

Calls 4

newFunction · 0.85
is_emptyMethod · 0.80
as_strMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected