X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=plugins%2Fmarkdown%2Fmarkdown.php;h=a764b6fa88520711ec6b46183894040055e6fe3a;hb=refs%2Fpull%2F701%2Fhead;hp=6b1c1d4433b8be80c32b7fc981e0effa97637661;hpb=0c4c7ae818336d5b0f94562e551ca1a3f34d3435;p=github%2Fshaarli%2FShaarli.git diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php index 6b1c1d44..a764b6fa 100644 --- a/plugins/markdown/markdown.php +++ b/plugins/markdown/markdown.php @@ -6,8 +6,6 @@ * Shaare's descriptions are parsed with Markdown. */ -require_once 'Parsedown.php'; - /* * If this tag is used on a shaare, the description won't be processed by Parsedown. */ @@ -157,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; @@ -175,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 );