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.php28
1 files changed, 21 insertions, 7 deletions
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index 821bb125..628970d6 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -7,6 +7,8 @@
7 */ 7 */
8 8
9use Shaarli\Config\ConfigManager; 9use Shaarli\Config\ConfigManager;
10use Shaarli\Plugin\PluginManager;
11use Shaarli\Router;
10 12
11/* 13/*
12 * If this tag is used on a shaare, the description won't be processed by Parsedown. 14 * If this tag is used on a shaare, the description won't be processed by Parsedown.
@@ -28,6 +30,7 @@ function hook_markdown_render_linklist($data, $conf)
28 $value = stripNoMarkdownTag($value); 30 $value = stripNoMarkdownTag($value);
29 continue; 31 continue;
30 } 32 }
33 $value['description_src'] = $value['description'];
31 $value['description'] = process_markdown( 34 $value['description'] = process_markdown(
32 $value['description'], 35 $value['description'],
33 $conf->get('security.markdown_escape', true), 36 $conf->get('security.markdown_escape', true),
@@ -138,7 +141,6 @@ function hook_markdown_render_includes($data)
138 || $data['_PAGE_'] == Router::$PAGE_DAILY 141 || $data['_PAGE_'] == Router::$PAGE_DAILY
139 || $data['_PAGE_'] == Router::$PAGE_EDITLINK 142 || $data['_PAGE_'] == Router::$PAGE_EDITLINK
140 ) { 143 ) {
141
142 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css'; 144 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css';
143 } 145 }
144 146
@@ -194,8 +196,7 @@ function reverse_text2clickable($description)
194 // Detect and toggle block of code 196 // Detect and toggle block of code
195 if (!$codeBlockOn) { 197 if (!$codeBlockOn) {
196 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0; 198 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
197 } 199 } elseif (preg_match('/^```/', $descriptionLine) > 0) {
198 elseif (preg_match('/^```/', $descriptionLine) > 0) {
199 $codeBlockOn = false; 200 $codeBlockOn = false;
200 } 201 }
201 202
@@ -215,6 +216,15 @@ function reverse_text2clickable($description)
215 $descriptionLine 216 $descriptionLine
216 ); 217 );
217 218
219 // Make hashtag links markdown ready, otherwise the links will be ignored with escape set to true
220 if (!$codeBlockOn && !$codeLineOn) {
221 $descriptionLine = preg_replace(
222 '#<a href="([^ ]*)"'. $hashtagTitle .'>([^<]+)</a>#m',
223 '[$2]($1)',
224 $descriptionLine
225 );
226 }
227
218 $descriptionOut .= $descriptionLine; 228 $descriptionOut .= $descriptionLine;
219 if ($lineCount++ < count($descriptionLines) - 1) { 229 if ($lineCount++ < count($descriptionLines) - 1) {
220 $descriptionOut .= PHP_EOL; 230 $descriptionOut .= PHP_EOL;
@@ -292,13 +302,17 @@ function sanitize_html($description)
292 foreach ($escapeTags as $tag) { 302 foreach ($escapeTags as $tag) {
293 $description = preg_replace_callback( 303 $description = preg_replace_callback(
294 '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is', 304 '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is',
295 function ($match) { return escape($match[0]); }, 305 function ($match) {
296 $description); 306 return escape($match[0]);
307 },
308 $description
309 );
297 } 310 }
298 $description = preg_replace( 311 $description = preg_replace(
299 '#(<[^>]+\s)on[a-z]*="?[^ "]*"?#is', 312 '#(<[^>]+\s)on[a-z]*="?[^ "]*"?#is',
300 '$1', 313 '$1',
301 $description); 314 $description
315 );
302 return $description; 316 return $description;
303} 317}
304 318
@@ -331,7 +345,7 @@ function process_markdown($description, $escape = true, $allowedProtocols = [])
331 ->text($processedDescription); 345 ->text($processedDescription);
332 $processedDescription = sanitize_html($processedDescription); 346 $processedDescription = sanitize_html($processedDescription);
333 347
334 if(!empty($processedDescription)){ 348 if (!empty($processedDescription)) {
335 $processedDescription = '<div class="markdown">'. $processedDescription . '</div>'; 349 $processedDescription = '<div class="markdown">'. $processedDescription . '</div>';
336 } 350 }
337 351