aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/markdown/markdown.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/markdown/markdown.php')
-rw-r--r--plugins/markdown/markdown.php26
1 files changed, 19 insertions, 7 deletions
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index 821bb125..8823af91 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -28,6 +28,7 @@ function hook_markdown_render_linklist($data, $conf)
28 $value = stripNoMarkdownTag($value); 28 $value = stripNoMarkdownTag($value);
29 continue; 29 continue;
30 } 30 }
31 $value['description_src'] = $value['description'];
31 $value['description'] = process_markdown( 32 $value['description'] = process_markdown(
32 $value['description'], 33 $value['description'],
33 $conf->get('security.markdown_escape', true), 34 $conf->get('security.markdown_escape', true),
@@ -138,7 +139,6 @@ function hook_markdown_render_includes($data)
138 || $data['_PAGE_'] == Router::$PAGE_DAILY 139 || $data['_PAGE_'] == Router::$PAGE_DAILY
139 || $data['_PAGE_'] == Router::$PAGE_EDITLINK 140 || $data['_PAGE_'] == Router::$PAGE_EDITLINK
140 ) { 141 ) {
141
142 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css'; 142 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css';
143 } 143 }
144 144
@@ -194,8 +194,7 @@ function reverse_text2clickable($description)
194 // Detect and toggle block of code 194 // Detect and toggle block of code
195 if (!$codeBlockOn) { 195 if (!$codeBlockOn) {
196 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0; 196 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
197 } 197 } elseif (preg_match('/^```/', $descriptionLine) > 0) {
198 elseif (preg_match('/^```/', $descriptionLine) > 0) {
199 $codeBlockOn = false; 198 $codeBlockOn = false;
200 } 199 }
201 200
@@ -215,6 +214,15 @@ function reverse_text2clickable($description)
215 $descriptionLine 214 $descriptionLine
216 ); 215 );
217 216
217 // Make hashtag links markdown ready, otherwise the links will be ignored with escape set to true
218 if (!$codeBlockOn && !$codeLineOn) {
219 $descriptionLine = preg_replace(
220 '#<a href="([^ ]*)"'. $hashtagTitle .'>([^<]+)</a>#m',
221 '[$2]($1)',
222 $descriptionLine
223 );
224 }
225
218 $descriptionOut .= $descriptionLine; 226 $descriptionOut .= $descriptionLine;
219 if ($lineCount++ < count($descriptionLines) - 1) { 227 if ($lineCount++ < count($descriptionLines) - 1) {
220 $descriptionOut .= PHP_EOL; 228 $descriptionOut .= PHP_EOL;
@@ -292,13 +300,17 @@ function sanitize_html($description)
292 foreach ($escapeTags as $tag) { 300 foreach ($escapeTags as $tag) {
293 $description = preg_replace_callback( 301 $description = preg_replace_callback(
294 '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is', 302 '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is',
295 function ($match) { return escape($match[0]); }, 303 function ($match) {
296 $description); 304 return escape($match[0]);
305 },
306 $description
307 );
297 } 308 }
298 $description = preg_replace( 309 $description = preg_replace(
299 '#(<[^>]+\s)on[a-z]*="?[^ "]*"?#is', 310 '#(<[^>]+\s)on[a-z]*="?[^ "]*"?#is',
300 '$1', 311 '$1',
301 $description); 312 $description
313 );
302 return $description; 314 return $description;
303} 315}
304 316
@@ -331,7 +343,7 @@ function process_markdown($description, $escape = true, $allowedProtocols = [])
331 ->text($processedDescription); 343 ->text($processedDescription);
332 $processedDescription = sanitize_html($processedDescription); 344 $processedDescription = sanitize_html($processedDescription);
333 345
334 if(!empty($processedDescription)){ 346 if (!empty($processedDescription)) {
335 $processedDescription = '<div class="markdown">'. $processedDescription . '</div>'; 347 $processedDescription = '<div class="markdown">'. $processedDescription . '</div>';
336 } 348 }
337 349