From 537706f39c15b0b5887d84c44657b754714c2540 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 25 Jan 2024 23:17:43 +0200 Subject: [PATCH] add document format filters --- src/controller/room.php | 49 ++++++++++++++++++++++++++++++++++------- src/view/post.gemini | 2 +- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/controller/room.php b/src/controller/room.php index 56db23f..db2a8e5 100644 --- a/src/controller/room.php +++ b/src/controller/room.php @@ -256,13 +256,22 @@ class Room if ($post['txid'] == $quote) { // Strip folding - $quote = + $quote = '>' . trim( preg_replace( '/^@([A-z0-9]{64})/', null, - $post['value'] - ) + // Add quote after each new line + str_replace( + PHP_EOL, + PHP_EOL . '>', + // Ignore markup + $this->_plain( + $post['value'] + ) + ) + ), + '>' ); break; @@ -270,7 +279,13 @@ class Room } // Remove mention from message - $record['value'] = preg_replace('/^@([A-z0-9]{64})/', null, $record['value']); + $record['value'] = preg_replace( + '/^@([A-z0-9]{64})/', + null, + $this->_plain( + $record['value'] + ) + ); } } @@ -292,10 +307,9 @@ class Room $matches[1] ), '@' . $matches[2], - trim( - $quote - ), - trim( + $quote + , + $this->_plain( $record['value'] ) ], @@ -380,4 +394,23 @@ class Room return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]]; } + + private function _plain(string $value) + { + return trim( + str_replace( + [ + '#', + '##', + '###', + '>', + '*', + '```', + '=>', + ], + null, + $value + ) + ); + } } \ No newline at end of file diff --git a/src/view/post.gemini b/src/view/post.gemini index ce19208..7e00175 100644 --- a/src/view/post.gemini +++ b/src/view/post.gemini @@ -1,5 +1,5 @@ ## {author} -> {quote} +{quote} {message} ``` {time} #{txid}