From 70ddd8063267c92403c3e962a595f30e0e0c2f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bugsounet=20-=20C=C3=A9dric?= Date: Sat, 11 Nov 2023 09:13:16 +0100 Subject: [PATCH] Use `html-to-text` instead of regex for transform description (#3264) I try to use only `html-to-text` library it's will solve issue #3235 @rejas, @sdetweil, @khassel: Can you do tests with your own feeds? Thanks for feedbacks --- CHANGELOG.md | 1 + modules/default/newsfeed/newsfeedfetcher.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9a7b915..3140c951 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ _This release is scheduled to be released on 2024-01-01._ ### Updated - Update electron to v27 and update other dependencies as well as github actions +- Update newsfeed: Use `html-to-text` instead of regex for transform description ### Fixed diff --git a/modules/default/newsfeed/newsfeedfetcher.js b/modules/default/newsfeed/newsfeedfetcher.js index 0f1b5d6c..0c52e347 100644 --- a/modules/default/newsfeed/newsfeedfetcher.js +++ b/modules/default/newsfeed/newsfeedfetcher.js @@ -52,10 +52,15 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings const url = item.url || item.link || ""; if (title && pubdate) { - const regex = /(<([^>]+)>)/gi; - description = description.toString().replace(regex, ""); // Convert HTML entities, codes and tag - description = htmlToText(description, { wordwrap: false }); + description = htmlToText(description, { + wordwrap: false, + selectors: [ + { selector: "a", options: { ignoreHref: true, noAnchorUrl: true } }, + { selector: "br", format: "inlineSurround", options: { prefix: " " } }, + { selector: "img", format: "skip" } + ] + }); items.push({ title: title,