remove html tags from description content

This commit is contained in:
Troy 2025-01-30 22:19:24 +00:00
parent 535ace44e3
commit 04ba3e64be
Signed by: troy
GPG key ID: DFC06C02ED3B4711
3 changed files with 20 additions and 3 deletions

View file

@ -16,9 +16,9 @@ On NixOS you can install Packard by including it as an input in flake.nix, then
inputs = {
packard.url = "github:troylusty/packard";
};
```
```nix
...
environment.systemPackages = {
inputs.packard.packages."${pkgs.system}".default
};

View file

@ -27,7 +27,7 @@ async fn main() -> Result<(), io::Error> {
"\x1b[1m>\x1b[0m \x1b[1;32m\x1b]8;;{}\x1b\\{}\x1b]8;;\x1b\\\x1b[0m\n\x1b[3m\x1b[2m{}\x1b[0m\n\x1b[2m{}\x1b[0m\n",
item.link,
item.title,
utils::trim_chars(&item.description),
utils::remove_html_tags(&utils::trim_chars(&item.description)),
item.pub_date.to_string()
);
}

View file

@ -7,3 +7,20 @@ pub fn trim_chars(input: &str) -> String {
trimmed
}
}
pub fn remove_html_tags(input: &str) -> String {
let mut result = String::new();
let mut in_tag = false;
for c in input.chars() {
if c == '<' {
in_tag = true;
} else if c == '>' {
in_tag = false;
} else if !in_tag {
result.push(c);
}
}
result
}