diff --git a/README.md b/README.md index 3a9a5ce..4a2a6b0 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,8 @@ With Nginx, you can use: rewrite ^(.+\.gmi)$ /htmgem.php?url=$1 last; ``` +## Install + +php-mbstring is required + So the page is available at [http://thesite/htmgem.php/directory/page.gmi]. diff --git a/htmgem.php b/htmgem.php index 74e7732..acc3a6f 100644 --- a/htmgem.php +++ b/htmgem.php @@ -47,14 +47,13 @@ EOL); * @param &$text where to replace. */ function markupPreg($instruction, $markup, &$text) { - #return preg_replace("#{$instruction}((?!{$instruction}.)+)(?:{$instruction})?#", "<{$markup}>$1", $text); $output = $text; # Replaces couples "__word__" into "word". - $output = preg_replace("#${instruction}(.+?)${instruction}#", "<{$markup}>$1", $output); + $output = mb_ereg_replace("${instruction}(.+?)${instruction}", "<{$markup}>\\1", $output); # Replaces a remaining __ into "" to the end of the line. - $output = preg_replace("#${instruction}(.+)?#", "<{$markup}>$1", $output); + $output = mb_ereg_replace("${instruction}(.+)?", "<{$markup}>\\1", $output); $text = $output; } @@ -77,7 +76,8 @@ function addTextAttributes(&$line) { */ function htmlEscape(&$text) { $text = htmlspecialchars($text, ENT_HTML5, "UTF-8", false); - $text = preg_replace("#\ ([?!;])#", " \$1", $text); # Espace fine insécable + $text = mb_ereg_replace("\ ([?!:;»€$])", " \\1", $text); # Espace fine insécable + $text = mb_ereg_replace("([«])\ ", "\\1 ", $text); # Espace fine insécable } $mode = null;