diff options
author | Mario <mario@mariovavti.com> | 2024-03-15 22:34:27 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-03-15 22:36:44 +0000 |
commit | d846cefade3e68c74f3767b43aa7d74df2044166 (patch) | |
tree | ad8e932317a23c80d7211628667f207211388c73 | |
parent | b68ddc4cd330a6806a5aeeb6f405eded425bc36b (diff) | |
download | volse-hubzilla-d846cefade3e68c74f3767b43aa7d74df2044166.tar.gz volse-hubzilla-d846cefade3e68c74f3767b43aa7d74df2044166.tar.bz2 volse-hubzilla-d846cefade3e68c74f3767b43aa7d74df2044166.zip |
adjust encrypted content representation and also add it to bb_to_markdown
(cherry picked from commit f3efdbf230657ce0c7ada803b97161b8fe4d5ae8)
-rw-r--r-- | include/bbcode.php | 14 | ||||
-rw-r--r-- | include/markdown.php | 23 |
2 files changed, 28 insertions, 9 deletions
diff --git a/include/bbcode.php b/include/bbcode.php index 20a866073..db4147c1e 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -297,20 +297,20 @@ function bb_parse_crypt($match) { */ function bb_parse_b64_crypt($match) { - if(empty($match[2])) + if(empty($match[1])) { return; + } + + $r = '-----BEGIN ENCRYPTED MESSAGE-----' . "\n"; + $r .= $match[1] . "\n"; + $r .= '-----END ENCRYPTED MESSAGE-----' . "\n"; - $r .= '<code>'; - $r .= '----- ENCRYPTED CONTENT -----' . '<br>'; - $r .= $match[2] . '<br>'; - $r .= '----- END ENCRYPTED CONTENT -----'; - $r .= '</code>'; + $r = '<code>' . str_replace("\n", '<br>', wordwrap($r, 75, "\n", true)) . '</code>'; return $r; } - function bb_parse_app($match) { $app = Zotlabs\Lib\Apps::app_decode($match[1]); diff --git a/include/markdown.php b/include/markdown.php index 7fba1259f..b2adcd0d5 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -221,6 +221,21 @@ function bb_to_markdown_transform_tags($match) { return '#'. str_replace(' ', '_', $match[3]); } +function bb_to_markdown_parse_b64_crypt($match) { + + if(empty($match[1])) { + return; + } + + $r = '```' . "\n"; + $r .= '-----BEGIN ENCRYPTED MESSAGE-----' . "\n"; + $r .= $match[1] . "\n"; + $r .= '-----END ENCRYPTED MESSAGE-----' . "\n"; + $r .= '```' . "\n"; + + return wordwrap($r, 75, "\n", true); + +} /** * @brief Convert bbcode to Markdown. @@ -244,6 +259,10 @@ function bb_to_markdown($Text, $options = []) { $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism", 'bb_to_markdown_share', $Text); + if (str_contains($Text, '[/crypt]')) { + $Text = preg_replace_callback("/\[crypt\](.*?)\[\/crypt\]/ism", 'bb_to_markdown_parse_b64_crypt', $Text); + } + $x = [ 'bbcode' => $Text, 'options' => $options ]; /** @@ -264,8 +283,8 @@ function bb_to_markdown($Text, $options = []) { // Now convert HTML to Markdown $Text = html2markdown($Text); - //html2markdown adds backslashes infront of hashes after a new line. remove them - $Text = str_replace("\n\#", "\n#", $Text); + //html2markdown adds backslashes infront of hashes and dashes after a new line. remove them + $Text = str_replace(["\n\#", "\n\-----"], ["\n#", "\n-----"], $Text); // If the text going into bbcode() has a plain URL in it, i.e. // with no [url] tags around it, it will come out of parseString() |