From 803cd74b4881a617a56be4fb5780d6d25fd5433f Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 30 Sep 2024 13:31:42 +0200 Subject: markdown: Don't link URLs in code blocks. When passing a content throught the `markdown_to_bb` function to convert any markdown in the content, any recognized URLs in the content would be converted to BBCode links as a post processing step after the main conversion. After commit a1ccacb825edac6ae36e5db4f62ebfe7aeaebe9f this did no longer consider content within code blocks, and would thus convert them as to BBCode links. Example: The following content [code] example url: https://example.com [/code] Would be converted to [code] example url: [url=https://example.com]https://example.com[/url] [/code] Prior to commit a1ccacb825edac6ae36e5db4f62ebfe7aeaebe9f, code blocks would be protected, so this would not happen. This patch removes the post processing step for converting plain URLs to links completely from this routine. This functionality is in any case covered in the actual BBCode parser where it belongs. This will have some other side effects as well, such as images and links created using Markdown, will not be converted to [zmg] or [zrl] tags where that would be done automatically before. If you intend to use a [zrl] or [zmg] tag, you now need to do so explicitly. --- include/markdown.php | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'include') diff --git a/include/markdown.php b/include/markdown.php index b2adcd0d5..90d671fe4 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -80,22 +80,6 @@ function markdown_to_bb($s, $use_zrl = false, $options = []) { $s = html2bbcode($s); - // $s = bb_code_protect($s); - - // Convert everything that looks like a link to a link - if($use_zrl) { - if (strpos($s,'[/img]') !== false) { - $s = preg_replace_callback("/\[img\](.*?)\[\/img\]/ism", 'use_zrl_cb_img', $s); - $s = preg_replace_callback("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", 'use_zrl_cb_img_x', $s); - } - $s = preg_replace_callback("/([^\]\=\{\/]|^)(https?\:\/\/)([a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)([\,\.\:\;]\s|$)/ismu", 'use_zrl_cb_link',$s); - } - else { - $s = preg_replace("/([^\]\=\{\/]|^)(https?\:\/\/)([a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@\(\)]+)([\,\.\:\;]\s|$)/ismu", '$1[url=$2$3]$2$3[/url]$4',$s); - } - - // $s = bb_code_unprotect($s); - // remove duplicate adjacent code tags $s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s); -- cgit v1.2.3