forked from k0a1a/hotglue2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_markdown.php
More file actions
56 lines (47 loc) · 1.66 KB
/
module_markdown.php
File metadata and controls
56 lines (47 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
use Michelf\Markdown;
/*
* module_markdown.inc.php
* Convert text fields to and from markdown
*
* This source code is licensed under the GNU General Public License.
* See the file COPYING for more details.
*/
@require_once('config.inc.php');
require_once('html.inc.php');
require_once('modules.inc.php');
$pages = [];
function markdown_alter_render_early($object) {
// Don't convert markdown in edit mode
if (isset($object['edit']) && $object['edit']) {
return $object;
}
// If Markdown is not installed, return
if (!class_exists('Michelf\Markdown')) {
log_msg('debug', 'Michelf Markdown is not installed, not converting text');
return $object;
}
$object['elem'] = markdown_text_nodes($object['elem']);
return $object;
}
function markdown_text_nodes($elem) {
if (is_array($elem) && !isset($elem['val'])) {
// If elem is an array, iterate through it
foreach ($elem as $key => $val) {
$elem[$key] = markdown_text_nodes($val);
}
} else if (is_array($elem) && isset($elem['val']) && is_array($elem['val'])) {
// If elem is an array with a 'val' key, check if 'val' is a string and set it
foreach ($elem['val'] as $key => $val) {
$elem['val'][$key] = markdown_text_nodes($val);
}
} else if (isset($elem['val']) && is_string($elem['val'])) {
// If elem is a string, render it with Markdown
// Only if val contains a newline character
//if (strpos($elem['val'], "\n") > 1) {
$elem['val'] = Markdown::defaultTransform($elem['val']);
$elem['class'][] = 'markdown';
//}
}
return $elem;
}