From 8ba453ebc499cdcca71290d92a505fdea451ce9e Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 1 Mar 2024 20:41:07 +0200 Subject: [PATCH] escape gemini text --- src/server.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/server.php b/src/server.php index 37fd879..624fce5 100644 --- a/src/server.php +++ b/src/server.php @@ -285,9 +285,15 @@ $server->setHandler( // Value $result[] = null; $result[] = trim( - preg_replace( // remove extra breaks - '/[\n\r]{3,}/', - PHP_EOL . PHP_EOL, + preg_replace( + [ + '/(^|\s+)(#|\*|```|=>)/', // escape gemini text + '/[\n\r]{3,}/', // remove extra breaks + ], + [ + '$1 $2', + PHP_EOL . PHP_EOL, + ], $record['value'] ) ); @@ -518,9 +524,15 @@ $server->setHandler( // Value $result[] = trim( - preg_replace( // remove extra breaks - '/[\n\r]{3,}/', - PHP_EOL . PHP_EOL, + preg_replace( + [ + '/(^|\s+)(#|\*|```|=>)/', // escape gemini text + '/[\n\r]{3,}/', // remove extra breaks + ], + [ + '$1 $2', + PHP_EOL . PHP_EOL, + ], $record['value'] ) );