From 8fe3d828cdca463b3d74f159bac16861447b4d88 Mon Sep 17 00:00:00 2001 From: Terence Ong Date: Wed, 8 Apr 2026 10:38:06 +0700 Subject: [PATCH] fix: strip source names from excerpts using nbsp separators Google News RSS excerpts use    (double non-breaking spaces) to separate the excerpt text from the source name. Added html_entity_decode and nbsp-based separators to handle this pattern. Co-Authored-By: Claude Opus 4.6 --- includes/class-peptide-news-rest-api.php | 13 ++++++++++++- .../includes/class-peptide-news-rest-api.php | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/includes/class-peptide-news-rest-api.php b/includes/class-peptide-news-rest-api.php index db4b737..d53c7af 100644 --- a/includes/class-peptide-news-rest-api.php +++ b/includes/class-peptide-news-rest-api.php @@ -192,7 +192,18 @@ class Peptide_News_Rest_API { return $text; } - $separators = array( ' - ', ' | ', ' — ', ' – ', ' // ' ); + // Decode HTML entities first so   becomes actual characters. + $text = html_entity_decode( $text, ENT_QUOTES | ENT_HTML5, 'UTF-8' ); + + // Common separators between title/excerpt and source name. + // Includes regular spaces, non-breaking spaces (\xC2\xA0), and typographic dashes. + $nbsp = "\xC2\xA0"; // UTF-8 non-breaking space + $separators = array( + ' - ', ' | ', ' — ', ' – ', ' // ', + $nbsp . $nbsp, // double non-breaking space (Google News RSS excerpts) + ' ', // double regular space + $nbsp, // single non-breaking space + ); // Build list of source names to try matching against. $source_names = array(); diff --git a/peptide-news-plugin/includes/class-peptide-news-rest-api.php b/peptide-news-plugin/includes/class-peptide-news-rest-api.php index f13777c..b5db289 100644 --- a/peptide-news-plugin/includes/class-peptide-news-rest-api.php +++ b/peptide-news-plugin/includes/class-peptide-news-rest-api.php @@ -183,7 +183,18 @@ class Peptide_News_Rest_API { return $text; } - $separators = array( ' - ', ' | ', ' — ', ' – ', ' // ' ); + // Decode HTML entities first so   becomes actual characters. + $text = html_entity_decode( $text, ENT_QUOTES | ENT_HTML5, 'UTF-8' ); + + // Common separators between title/excerpt and source name. + // Includes regular spaces, non-breaking spaces (\xC2\xA0), and typographic dashes. + $nbsp = "\xC2\xA0"; // UTF-8 non-breaking space + $separators = array( + ' - ', ' | ', ' — ', ' – ', ' // ', + $nbsp . $nbsp, // double non-breaking space (Google News RSS excerpts) + ' ', // double regular space + $nbsp, // single non-breaking space + ); // Build list of source names to try matching against. $source_names = array();