widget/reply: formatting syntax for *bold*
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 14 May 2021 15:20:38 +0000 (17:20 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 17 May 2021 18:53:38 +0000 (20:53 +0200)
Common chat format but unlike more complicated Markdown **doubling**.

upload.inc.php

index 10881a24a0f9317216339e0b88dc65232afc0207..d7d572d31959a5d461240b89072c2eb60f0293d3 100644 (file)
@@ -51,10 +51,13 @@ function messagehtml($input)
        if ($User->admin and preg_match('/\A<[a-z][^>]*>/', $input)) {
                return $input;  # allow html input as is if privileged
        }
-       $html = preg_replace(
-               ["/\r\n?/", "/  +\n/", "/\n/",      '/\b_(\w+)_\b/'],
-               ["\n",      "<br />",  "</p>\n<p>", '<em>$1</em>'  ],
-               htmlspecialchars($input)
-       );
+       $markup = [
+               "/\r\n?/" => "\n",        # unix newlines
+               "/  +\n/" => "<br />",    # trailing spaces for hard line break
+               "/\n/"    => "</p>\n<p>", # newlines start paragraphs
+               '/\b_(\w+)_\b/'   => '<em>$1</em>',         # italic
+               '/\b\*(\w+)\*\b/' => '<strong>$1</strong>', # bold
+       ];
+       $html = preg_replace(array_keys($markup), array_values($markup), htmlspecialchars($input));
        return "<p>$html</p>";
 }