From c5941f316a49c94eff354b63e75b3add98ac4aea Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 21 Oct 2016 12:38:38 +0200 Subject: Fix an issue with links not being reversed in code blocks Fixes #672 + Markdown to HTML unit test --- plugins/markdown/markdown.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'plugins/markdown') diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php index eb7bf23d..a764b6fa 100644 --- a/plugins/markdown/markdown.php +++ b/plugins/markdown/markdown.php @@ -155,8 +155,9 @@ function reverse_text2clickable($description) $lineCount = 0; foreach ($descriptionLines as $descriptionLine) { - // Detect line of code - $codeLineOn = preg_match('/^ /', $descriptionLine) > 0; + // Detect line of code: starting with 4 spaces, + // except lists which can start with +/*/- or `2.` after spaces. + $codeLineOn = preg_match('/^ +(?=[^\+\*\-])(?=(?!\d\.).)/', $descriptionLine) > 0; // Detect and toggle block of code if (!$codeBlockOn) { $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0; @@ -173,10 +174,10 @@ function reverse_text2clickable($description) $descriptionLine ); - // Reverse hashtag links if we're in a code block. - $hashtagFilter = ($codeBlockOn || $codeLineOn) ? $hashtagTitle : ''; + // Reverse all links in code blocks, only non hashtag elsewhere. + $hashtagFilter = (!$codeBlockOn && !$codeLineOn) ? '(?!'. $hashtagTitle .')': '(?:'. $hashtagTitle .')?'; $descriptionLine = preg_replace( - '!([^<]+)!m', + '#([^<]+)#m', '$1', $descriptionLine ); -- cgit v1.2.3