From d5f569baa9f7da9c30704d96da4349190d11b192 Mon Sep 17 00:00:00 2001 From: Christophe HENRY Date: Mon, 8 Mar 2021 10:06:07 +0100 Subject: [PATCH] Manages more dashes --- htmgem.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htmgem.php b/htmgem.php index acd5bd2..9771c6c 100644 --- a/htmgem.php +++ b/htmgem.php @@ -55,6 +55,13 @@ function addTextAttributes(&$line) { } define("NARROW_NO_BREAK_SPACE", " "); +define("DASHES" + ,"‒" # U+2012 Figure Dash + ."–" # U+2013 En Dash + ."—" # U+2014 Em Dash + ."⸺" # U+2E3A Two-Em Dash + ."⸻" # U+2E3B Three-Em Dash (Three times larger than a single char) +); /** * Prepares the raw text to be displayed in HTML environment: @@ -67,11 +74,9 @@ function htmlPrepare(&$text) { $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); - + # Warning: using a monospace font editor may not display dashes as they should be! # 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); + $text = mb_ereg_replace("([".DASHES."]) ([^".DASHES.".]+) ([".DASHES."])", "\\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);