Apply the en dash to number ranges in stories.

A typo ($stort) threw the result away.
This commit is contained in:
tim
2026-09-25 22:11:31 +02:00
parent f78fd09710
commit 601df8a9be
+6 -2
View File
@@ -237,8 +237,12 @@ function sanitise($story) {
$story = preg_replace("#<script[^>]*?>.*?</script>#si", "", $story);
// No comments please!
$story = preg_replace("#<!--.*?-->#si", "", $story);
// Replace number ranges with n-dashes
$stort = preg_replace("#(\d)-+(\d)#si", "$1&ndash;$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&ndash;", $parts[$i]);
$story = implode('', $parts);
// Replace " -- " and "--" with m-dashes
$story = preg_replace("#(\s?)--(\s?)#si", "$1&mdash;$2", $story);
// Replace ellipses