]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/markdown/markdown.php
6 * Shaare's descriptions are parsed with Markdown.
9 require_once 'Parsedown.php';
12 * Parse linklist descriptions.
14 * @param array $data linklist data.
16 * @return mixed linklist data parsed in markdown (and converted to HTML).
18 function hook_markdown_render_linklist($data)
20 foreach ($data['links'] as &$value) {
21 $value['description'] = process_markdown($value['description']);
28 * Parse daily descriptions.
30 * @param array $data daily data.
32 * @return mixed daily data parsed in markdown (and converted to HTML).
34 function hook_markdown_render_daily($data)
36 // Manipulate columns data
37 foreach ($data['cols'] as &$value) {
38 foreach ($value as &$value2) {
39 $value2['formatedDescription'] = process_markdown($value2['formatedDescription']);
47 * When link list is displayed, include markdown CSS.
49 * @param array $data includes data.
51 * @return mixed - includes data with markdown CSS file added.
53 function hook_markdown_render_includes($data)
55 if ($data['_PAGE_'] == Router
::$PAGE_LINKLIST
56 || $data['_PAGE_'] == Router
::$PAGE_DAILY
57 || $data['_PAGE_'] == Router
::$PAGE_EDITLINK
60 $data['css_files'][] = PluginManager
::$PLUGINS_PATH . '/markdown/markdown.css';
67 * Hook render_editlink.
68 * Adds an help link to markdown syntax.
70 * @param array $data data passed to plugin
72 * @return array altered $data.
74 function hook_markdown_render_editlink($data)
76 // Load help HTML into a string
77 $data['edit_link_plugin'][] = file_get_contents(PluginManager
::$PLUGINS_PATH .'/markdown/help.html');
83 * Remove HTML links auto generated by Shaarli core system.
84 * Keeps HREF attributes.
86 * @param string $description input description text.
88 * @return string $description without HTML links.
90 function reverse_text2clickable($description)
92 return preg_replace('!<a +href="([^ ]*)">[^ ]+</a>!m', '$1', $description);
96 * Remove <br> tag to let markdown handle it.
98 * @param string $description input description text.
100 * @return string $description without <br> tags.
102 function reverse_nl2br($description)
104 return preg_replace('!<br */
?>!im
', '', $description);
108 * Remove HTML spaces ' 
;' auto generated by Shaarli core system.
110 * @param string $description input description text.
112 * @return string $description without HTML links.
114 function reverse_space2nbsp($description)
116 return preg_replace('/(^
| ) 
;/m
', '$1 ', $description);
120 * Remove '>
;' at start of line auto generated by Shaarli core system
121 * to allow markdown blockquotes.
123 * @param string $description input description text.
125 * @return string $description without HTML links.
127 function reset_quote_tags($description)
129 return preg_replace('/^
( *)>
; /m
', '$1> ', $description);
133 * Render shaare contents through Markdown parser.
134 * 1. Remove HTML generated by Shaarli core.
135 * 2. Generate markdown descriptions.
136 * 3. Wrap description in 'markdown
' CSS class.
138 * @param string $description input description text.
140 * @return string HTML processed $description.
142 function process_markdown($description)
144 $parsedown = new Parsedown();
146 $processedDescription = $description;
147 $processedDescription = reverse_text2clickable($processedDescription);
148 $processedDescription = reverse_nl2br($processedDescription);
149 $processedDescription = reverse_space2nbsp($processedDescription);
150 $processedDescription = reset_quote_tags($processedDescription);
151 $processedDescription = $parsedown
152 ->setMarkupEscaped(false)
153 ->setBreaksEnabled(true)
154 ->text($processedDescription);
155 $processedDescription = '<div
class="markdown">'. $processedDescription . '</div
>';
157 return $processedDescription;