From f64db8c7ca1a2d7649f94c67ce97066051df9853 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Sat, 6 Mar 2021 15:36:56 +0000 Subject: [PATCH] Manages non-break spaces for em-dash and en-dash --- htmgem.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htmgem.php b/htmgem.php index dc09be4..acd5bd2 100644 --- a/htmgem.php +++ b/htmgem.php @@ -66,6 +66,15 @@ function htmlPrepare(&$text) { $text = htmlspecialchars($text, ENT_HTML5|ENT_NOQUOTES, "UTF-8", false); $text = mb_ereg_replace("\ ([?!:;»€$])", NARROW_NO_BREAK_SPACE."\\1", $text); $text = mb_ereg_replace("([«])\ ", "\\1".NARROW_NO_BREAK_SPACE, $text); # Espace fine insécable + + # Below, "Em Dash" (U+2014, —) and "En Dash" (U+2013, –) make —– + #$text = mb_ereg_replace("([—–]) ([^—–.]+)( [—–]|\.)", "\\1".NARROW_NO_BREAK_SPACE."\\2".NARROW_NO_BREAK_SPACE."\\3", $text); + + # Adds no-break spaces to stick the (EM/EN dashes) to words : aaaaaa – bb – ccccc ==> aaaaaa –$bb$– ccccc + $text = mb_ereg_replace("([—–]) ([^—–.]+) ([—–])", "\\1".NARROW_NO_BREAK_SPACE."\\2".NARROW_NO_BREAK_SPACE."\\3", $text); + + # Adds no-break space to stick the (EM/EN dashes) to words : aaaaaa – bb. ==> aaaaaa –$bb. + $text = mb_ereg_replace("([—–]) ([^.]+).", "\\1".NARROW_NO_BREAK_SPACE."\\2.", $text); } ob_start();