aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/markdown')
-rw-r--r--plugins/markdown/markdown.php57
1 files changed, 38 insertions, 19 deletions
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index 1531549d..8823af91 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -6,6 +6,8 @@
6 * Shaare's descriptions are parsed with Markdown. 6 * Shaare's descriptions are parsed with Markdown.
7 */ 7 */
8 8
9use Shaarli\Config\ConfigManager;
10
9/* 11/*
10 * If this tag is used on a shaare, the description won't be processed by Parsedown. 12 * If this tag is used on a shaare, the description won't be processed by Parsedown.
11 */ 13 */
@@ -26,6 +28,7 @@ function hook_markdown_render_linklist($data, $conf)
26 $value = stripNoMarkdownTag($value); 28 $value = stripNoMarkdownTag($value);
27 continue; 29 continue;
28 } 30 }
31 $value['description_src'] = $value['description'];
29 $value['description'] = process_markdown( 32 $value['description'] = process_markdown(
30 $value['description'], 33 $value['description'],
31 $conf->get('security.markdown_escape', true), 34 $conf->get('security.markdown_escape', true),
@@ -50,6 +53,7 @@ function hook_markdown_render_feed($data, $conf)
50 $value = stripNoMarkdownTag($value); 53 $value = stripNoMarkdownTag($value);
51 continue; 54 continue;
52 } 55 }
56 $value['description'] = reverse_feed_permalink($value['description']);
53 $value['description'] = process_markdown( 57 $value['description'] = process_markdown(
54 $value['description'], 58 $value['description'],
55 $conf->get('security.markdown_escape', true), 59 $conf->get('security.markdown_escape', true),
@@ -70,19 +74,18 @@ function hook_markdown_render_feed($data, $conf)
70 */ 74 */
71function hook_markdown_render_daily($data, $conf) 75function hook_markdown_render_daily($data, $conf)
72{ 76{
77 //var_dump($data);die;
73 // Manipulate columns data 78 // Manipulate columns data
74 foreach ($data['cols'] as &$value) { 79 foreach ($data['linksToDisplay'] as &$value) {
75 foreach ($value as &$value2) { 80 if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
76 if (!empty($value2['tags']) && noMarkdownTag($value2['tags'])) { 81 $value = stripNoMarkdownTag($value);
77 $value2 = stripNoMarkdownTag($value2); 82 continue;
78 continue;
79 }
80 $value2['formatedDescription'] = process_markdown(
81 $value2['formatedDescription'],
82 $conf->get('security.markdown_escape', true),
83 $conf->get('security.allowed_protocols')
84 );
85 } 83 }
84 $value['formatedDescription'] = process_markdown(
85 $value['formatedDescription'],
86 $conf->get('security.markdown_escape', true),
87 $conf->get('security.allowed_protocols')
88 );
86 } 89 }
87 90
88 return $data; 91 return $data;
@@ -136,7 +139,6 @@ function hook_markdown_render_includes($data)
136 || $data['_PAGE_'] == Router::$PAGE_DAILY 139 || $data['_PAGE_'] == Router::$PAGE_DAILY
137 || $data['_PAGE_'] == Router::$PAGE_EDITLINK 140 || $data['_PAGE_'] == Router::$PAGE_EDITLINK
138 ) { 141 ) {
139
140 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css'; 142 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css';
141 } 143 }
142 144
@@ -192,8 +194,7 @@ function reverse_text2clickable($description)
192 // Detect and toggle block of code 194 // Detect and toggle block of code
193 if (!$codeBlockOn) { 195 if (!$codeBlockOn) {
194 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0; 196 $codeBlockOn = preg_match('/^```/', $descriptionLine) > 0;
195 } 197 } elseif (preg_match('/^```/', $descriptionLine) > 0) {
196 elseif (preg_match('/^```/', $descriptionLine) > 0) {
197 $codeBlockOn = false; 198 $codeBlockOn = false;
198 } 199 }
199 200
@@ -213,6 +214,15 @@ function reverse_text2clickable($description)
213 $descriptionLine 214 $descriptionLine
214 ); 215 );
215 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
216 $descriptionOut .= $descriptionLine; 226 $descriptionOut .= $descriptionLine;
217 if ($lineCount++ < count($descriptionLines) - 1) { 227 if ($lineCount++ < count($descriptionLines) - 1) {
218 $descriptionOut .= PHP_EOL; 228 $descriptionOut .= PHP_EOL;
@@ -245,6 +255,11 @@ function reverse_space2nbsp($description)
245 return preg_replace('/(^| )&nbsp;/m', '$1 ', $description); 255 return preg_replace('/(^| )&nbsp;/m', '$1 ', $description);
246} 256}
247 257
258function reverse_feed_permalink($description)
259{
260 return preg_replace('@&#8212; <a href="([^"]+)" title="[^"]+">(\w+)</a>$@im', '&#8212; [$2]($1)', $description);
261}
262
248/** 263/**
249 * Replace not whitelisted protocols with http:// in given description. 264 * Replace not whitelisted protocols with http:// in given description.
250 * 265 *
@@ -285,13 +300,17 @@ function sanitize_html($description)
285 foreach ($escapeTags as $tag) { 300 foreach ($escapeTags as $tag) {
286 $description = preg_replace_callback( 301 $description = preg_replace_callback(
287 '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is', 302 '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is',
288 function ($match) { return escape($match[0]); }, 303 function ($match) {
289 $description); 304 return escape($match[0]);
305 },
306 $description
307 );
290 } 308 }
291 $description = preg_replace( 309 $description = preg_replace(
292 '#(<[^>]+)on[a-z]*="?[^ "]*"?#is', 310 '#(<[^>]+\s)on[a-z]*="?[^ "]*"?#is',
293 '$1', 311 '$1',
294 $description); 312 $description
313 );
295 return $description; 314 return $description;
296} 315}
297 316
@@ -324,7 +343,7 @@ function process_markdown($description, $escape = true, $allowedProtocols = [])
324 ->text($processedDescription); 343 ->text($processedDescription);
325 $processedDescription = sanitize_html($processedDescription); 344 $processedDescription = sanitize_html($processedDescription);
326 345
327 if(!empty($processedDescription)){ 346 if (!empty($processedDescription)) {
328 $processedDescription = '<div class="markdown">'. $processedDescription . '</div>'; 347 $processedDescription = '<div class="markdown">'. $processedDescription . '</div>';
329 } 348 }
330 349