aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/markdown')
-rw-r--r--plugins/markdown/README.md21
-rw-r--r--plugins/markdown/markdown.php27
2 files changed, 34 insertions, 14 deletions
diff --git a/plugins/markdown/README.md b/plugins/markdown/README.md
index c64a831a..aafcf066 100644
--- a/plugins/markdown/README.md
+++ b/plugins/markdown/README.md
@@ -20,26 +20,35 @@ The directory structure should look like:
20 |--- markdown.css 20 |--- markdown.css
21 |--- markdown.meta 21 |--- markdown.meta
22 |--- markdown.php 22 |--- markdown.php
23 |--- Parsedown.php
24 |--- README.md 23 |--- README.md
25``` 24```
26 25
27To enable the plugin, just check it in the plugin administration page. 26To enable the plugin, just check it in the plugin administration page.
28 27
29You can also add `markdown` to your list of enabled plugins in `data/config.php` 28You can also add `markdown` to your list of enabled plugins in `data/config.json.php`
30(`ENABLED_PLUGINS` array). 29(`general.enabled_plugins` list).
31 30
32This should look like: 31This should look like:
33 32
34``` 33```
35$GLOBALS['config']['ENABLED_PLUGINS'] = array('qrcode', 'any_other_plugin', 'markdown') 34"general": {
35 "enabled_plugins": [
36 "markdown",
37 [...]
38 ],
39}
36``` 40```
37 41
42Parsedown parsing library is imported using Composer. If you installed Shaarli using `git`,
43or the `master` branch, run
44
45 composer update --no-dev --prefer-dist
46
38### No Markdown tag 47### No Markdown tag
39 48
40If the tag `.nomarkdown` is set for a shaare, it won't be converted to Markdown syntax. 49If the tag `nomarkdown` is set for a shaare, it won't be converted to Markdown syntax.
41 50
42> Note: it's a private tag (leading dot), so it won't be displayed to visitors. 51> Note: this is a special tag, so it won't be displayed in link list.
43 52
44### HTML rendering 53### HTML rendering
45 54
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index a764b6fa..0cf6e6e2 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -22,7 +22,7 @@ function hook_markdown_render_linklist($data)
22{ 22{
23 foreach ($data['links'] as &$value) { 23 foreach ($data['links'] as &$value) {
24 if (!empty($value['tags']) && noMarkdownTag($value['tags'])) { 24 if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
25 $value['taglist'] = stripNoMarkdownTag($value['taglist']); 25 $value = stripNoMarkdownTag($value);
26 continue; 26 continue;
27 } 27 }
28 $value['description'] = process_markdown($value['description']); 28 $value['description'] = process_markdown($value['description']);
@@ -41,7 +41,7 @@ function hook_markdown_render_feed($data)
41{ 41{
42 foreach ($data['links'] as &$value) { 42 foreach ($data['links'] as &$value) {
43 if (!empty($value['tags']) && noMarkdownTag($value['tags'])) { 43 if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
44 $value['tags'] = stripNoMarkdownTag($value['tags']); 44 $value = stripNoMarkdownTag($value);
45 continue; 45 continue;
46 } 46 }
47 $value['description'] = process_markdown($value['description']); 47 $value['description'] = process_markdown($value['description']);
@@ -63,6 +63,7 @@ function hook_markdown_render_daily($data)
63 foreach ($data['cols'] as &$value) { 63 foreach ($data['cols'] as &$value) {
64 foreach ($value as &$value2) { 64 foreach ($value as &$value2) {
65 if (!empty($value2['tags']) && noMarkdownTag($value2['tags'])) { 65 if (!empty($value2['tags']) && noMarkdownTag($value2['tags'])) {
66 $value2 = stripNoMarkdownTag($value2);
66 continue; 67 continue;
67 } 68 }
68 $value2['formatedDescription'] = process_markdown($value2['formatedDescription']); 69 $value2['formatedDescription'] = process_markdown($value2['formatedDescription']);
@@ -81,20 +82,30 @@ function hook_markdown_render_daily($data)
81 */ 82 */
82function noMarkdownTag($tags) 83function noMarkdownTag($tags)
83{ 84{
84 return strpos($tags, NO_MD_TAG) !== false; 85 return preg_match('/(^|\s)'. NO_MD_TAG .'(\s|$)/', $tags);
85} 86}
86 87
87/** 88/**
88 * Remove the no-markdown meta tag so it won't be displayed. 89 * Remove the no-markdown meta tag so it won't be displayed.
89 * 90 *
90 * @param string $tags Tag list. 91 * @param array $link Link data.
91 * 92 *
92 * @return string tag list without no markdown tag. 93 * @return array Updated link without no markdown tag.
93 */ 94 */
94function stripNoMarkdownTag($tags) 95function stripNoMarkdownTag($link)
95{ 96{
96 unset($tags[array_search(NO_MD_TAG, $tags)]); 97 if (! empty($link['taglist'])) {
97 return array_values($tags); 98 $offset = array_search(NO_MD_TAG, $link['taglist']);
99 if ($offset !== false) {
100 unset($link['taglist'][$offset]);
101 }
102 }
103
104 if (!empty($link['tags'])) {
105 str_replace(NO_MD_TAG, '', $link['tags']);
106 }
107
108 return $link;
98} 109}
99 110
100/** 111/**