From 04a1a7a24edbf8423a48f51609d545a5a7a3eb42 Mon Sep 17 00:00:00 2001
From: Mischa POSLAWSKY
Date: Fri, 14 May 2021 17:20:38 +0200
Subject: [PATCH] widget/reply: formatting syntax for *bold*
Common chat format but unlike more complicated Markdown **doubling**.
---
upload.inc.php | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/upload.inc.php b/upload.inc.php
index 10881a2..d7d572d 100644
--- a/upload.inc.php
+++ b/upload.inc.php
@@ -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", "
", "
\n", '$1' ],
- htmlspecialchars($input)
- );
+ $markup = [
+ "/\r\n?/" => "\n", # unix newlines
+ "/ +\n/" => "
", # trailing spaces for hard line break
+ "/\n/" => "
\n", # newlines start paragraphs
+ '/\b_(\w+)_\b/' => '$1', # italic
+ '/\b\*(\w+)\*\b/' => '$1', # bold
+ ];
+ $html = preg_replace(array_keys($markup), array_values($markup), htmlspecialchars($input));
return "
$html
";
}
--
2.30.0