-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathMarkdown.php
More file actions
70 lines (58 loc) · 1.41 KB
/
Markdown.php
File metadata and controls
70 lines (58 loc) · 1.41 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* PHP Command Line Tools
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.
*
* @author Ryan Sullivan <rsullivan@connectstudios.com>
* @copyright 2010 James Logsdom (http://girsbrain.org)
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace cli\tree;
/**
* The ASCII renderer renders trees with ASCII lines.
*/
class Markdown extends Renderer {
/**
* How many spaces to indent by
* @var int
*/
protected $_padding = 2;
/**
* @param int $padding Optional. Default 2.
*/
function __construct($padding = null)
{
if ($padding)
{
$this->_padding = $padding;
}
}
/**
* Renders the tree
*
* @param array $tree
* @param int $level Optional
* @return string
*/
public function render(array $tree, $level = 0)
{
$output = '';
foreach ($tree as $label => $next)
{
if (is_string($next))
{
$label = $next;
}
// Output the label
$output .= sprintf("%s- %s\n", str_repeat(' ', $level * $this->_padding), $label);
// Next level
if (is_array($next))
{
$output .= $this->render($next, $level + 1);
}
}
return $output;
}
}