From 04ba3e64be9d772564ee23d0a3434ddcce99464a Mon Sep 17 00:00:00 2001 From: Troy Date: Thu, 30 Jan 2025 22:19:24 +0000 Subject: [PATCH] remove html tags from description content --- README.md | 4 ++-- src/main.rs | 2 +- src/utils.rs | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 45a684a..9863d77 100644 --- a/README.md +++ b/README.md @@ -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 }; diff --git a/src/main.rs b/src/main.rs index 9e33a83..647d8ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() ); } diff --git a/src/utils.rs b/src/utils.rs index ce6124d..6d1f02d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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 +}