aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/markdown/markdown.php41
1 files changed, 39 insertions, 2 deletions
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index 5f56ecc2..6b1c1d44 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -151,7 +151,44 @@ function hook_markdown_render_editlink($data)
151 */ 151 */
152function reverse_text2clickable($description) 152function reverse_text2clickable($description)
153{ 153{
154 return preg_replace('!<a +href="([^ ]*)">[^ ]+</a>!m', '$1', $description); 154 $descriptionLines = explode(PHP_EOL, $description);
155 $descriptionOut = '';
156 $codeBlockOn = false;
157 $lineCount = 0;
158
159 foreach ($descriptionLines as $descriptionLine) {
160 // Detect line of code
161 $codeLineOn = preg_match('/^ /', $descriptionLine) > 0;
162 // Detect and toggle block of code
163 if (!$codeBlockOn) {
164 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
165 }
166 elseif (preg_match('/^```/', $descriptionLine) > 0) {
167 $codeBlockOn = false;
168 }
169
170 $hashtagTitle = ' title="Hashtag [^"]+"';
171 // Reverse `inline code` hashtags.
172 $descriptionLine = preg_replace(
173 '!(`[^`\n]*)<a href="[^ ]*"'. $hashtagTitle .'>([^<]+)</a>([^`\n]*`)!m',
174 '$1$2$3',
175 $descriptionLine
176 );
177
178 // Reverse hashtag links if we're in a code block.
179 $hashtagFilter = ($codeBlockOn || $codeLineOn) ? $hashtagTitle : '';
180 $descriptionLine = preg_replace(
181 '!<a href="[^ ]*"'. $hashtagFilter .'>([^<]+)</a>!m',
182 '$1',
183 $descriptionLine
184 );
185
186 $descriptionOut .= $descriptionLine;
187 if ($lineCount++ < count($descriptionLines) - 1) {
188 $descriptionOut .= PHP_EOL;
189 }
190 }
191 return $descriptionOut;
155} 192}
156 193
157/** 194/**
@@ -226,9 +263,9 @@ function process_markdown($description)
226 $parsedown = new Parsedown(); 263 $parsedown = new Parsedown();
227 264
228 $processedDescription = $description; 265 $processedDescription = $description;
229 $processedDescription = reverse_text2clickable($processedDescription);
230 $processedDescription = reverse_nl2br($processedDescription); 266 $processedDescription = reverse_nl2br($processedDescription);
231 $processedDescription = reverse_space2nbsp($processedDescription); 267 $processedDescription = reverse_space2nbsp($processedDescription);
268 $processedDescription = reverse_text2clickable($processedDescription);
232 $processedDescription = unescape($processedDescription); 269 $processedDescription = unescape($processedDescription);
233 $processedDescription = $parsedown 270 $processedDescription = $parsedown
234 ->setMarkupEscaped(false) 271 ->setMarkupEscaped(false)