aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/markdown/markdown.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam+github@flibidi.net>2016-10-22 12:53:15 +0200
committerGitHub <noreply@github.com>2016-10-22 12:53:15 +0200
commit761b4e283737a48934457855448df98e8014ba73 (patch)
tree3a98fc6dee7edd3a13f335f97fb9bc4faf95f064 /plugins/markdown/markdown.php
parent3d5e0aede31e07f060e3ca470d36374c54d5040c (diff)
parentc5941f316a49c94eff354b63e75b3add98ac4aea (diff)
downloadShaarli-761b4e283737a48934457855448df98e8014ba73.tar.gz
Shaarli-761b4e283737a48934457855448df98e8014ba73.tar.zst
Shaarli-761b4e283737a48934457855448df98e8014ba73.zip
Merge pull request #674 from ArthurHoaro/parsedown-composer
Use Composer for Parsedown and fix an issue with links
Diffstat (limited to 'plugins/markdown/markdown.php')
-rw-r--r--plugins/markdown/markdown.php13
1 files changed, 6 insertions, 7 deletions
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 @@
6 * Shaare's descriptions are parsed with Markdown. 6 * Shaare's descriptions are parsed with Markdown.
7 */ 7 */
8 8
9require_once 'Parsedown.php';
10
11/* 9/*
12 * If this tag is used on a shaare, the description won't be processed by Parsedown. 10 * If this tag is used on a shaare, the description won't be processed by Parsedown.
13 */ 11 */
@@ -157,8 +155,9 @@ function reverse_text2clickable($description)
157 $lineCount = 0; 155 $lineCount = 0;
158 156
159 foreach ($descriptionLines as $descriptionLine) { 157 foreach ($descriptionLines as $descriptionLine) {
160 // Detect line of code 158 // Detect line of code: starting with 4 spaces,
161 $codeLineOn = preg_match('/^ /', $descriptionLine) > 0; 159 // except lists which can start with +/*/- or `2.` after spaces.
160 $codeLineOn = preg_match('/^ +(?=[^\+\*\-])(?=(?!\d\.).)/', $descriptionLine) > 0;
162 // Detect and toggle block of code 161 // Detect and toggle block of code
163 if (!$codeBlockOn) { 162 if (!$codeBlockOn) {
164 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0; 163 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
@@ -175,10 +174,10 @@ function reverse_text2clickable($description)
175 $descriptionLine 174 $descriptionLine
176 ); 175 );
177 176
178 // Reverse hashtag links if we're in a code block. 177 // Reverse all links in code blocks, only non hashtag elsewhere.
179 $hashtagFilter = ($codeBlockOn || $codeLineOn) ? $hashtagTitle : ''; 178 $hashtagFilter = (!$codeBlockOn && !$codeLineOn) ? '(?!'. $hashtagTitle .')': '(?:'. $hashtagTitle .')?';
180 $descriptionLine = preg_replace( 179 $descriptionLine = preg_replace(
181 '!<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>!m', 180 '#<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>#m',
182 '$1', 181 '$1',
183 $descriptionLine 182 $descriptionLine
184 ); 183 );