From 601df8a9be86426c0a5d3c332a7bd4857c84d73c Mon Sep 17 00:00:00 2001 From: Timothy Allen Date: Fri, 25 Sep 2026 22:11:31 +0200 Subject: [PATCH] Apply the en dash to number ranges in stories. A typo ($stort) threw the result away. --- publish/post.lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/publish/post.lib.php b/publish/post.lib.php index 9304b93..2292a7e 100644 --- a/publish/post.lib.php +++ b/publish/post.lib.php @@ -237,8 +237,12 @@ function sanitise($story) { $story = preg_replace("#]*?>.*?#si", "", $story); // No comments please! $story = preg_replace("##si", "", $story); - // Replace number ranges with n-dashes - $stort = preg_replace("#(\d)-+(\d)#si", "$1–$2", $story); + // Replace number ranges with n-dashes, in the text only (not in tags, + // where the digits can be part of a link or an attribute) + $parts = preg_split("#(<[^>]*>)#", $story, -1, PREG_SPLIT_DELIM_CAPTURE); + for ($i = 0; $i < count($parts); $i += 2) + $parts[$i] = preg_replace("#(\d)-+(?=\d)#", "$1–", $parts[$i]); + $story = implode('', $parts); // Replace " -- " and "--" with m-dashes $story = preg_replace("#(\s?)--(\s?)#si", "$1—$2", $story); // Replace ellipses