aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/markdown
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2019-02-23 16:27:33 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-02-23 16:27:33 +0100
commit43c77f658a905e2def6aeca4c092683977cd0c55 (patch)
treecb0dc273a315a777847d251f856625b2fc779c04 /plugins/markdown
parent630ebca2b6359e942e5b6c057cca2b6069c1093a (diff)
parent1826e383ecf501302974132fd443cf1ca06e10f6 (diff)
downloadShaarli-43c77f658a905e2def6aeca4c092683977cd0c55.tar.gz
Shaarli-43c77f658a905e2def6aeca4c092683977cd0c55.tar.zst
Shaarli-43c77f658a905e2def6aeca4c092683977cd0c55.zip
Merge commit '1826e383ecf501302974132fd443cf1ca06e10f6' into v0.10
Diffstat (limited to 'plugins/markdown')
-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