@@ 11-40 (lines=30) @@ | ||
8 | * @see http://parsedown.org/ |
|
9 | * @author Matthias Glaub <[email protected]> |
|
10 | */ |
|
11 | class ErusevParsedownAdapter implements MarkdownAdapterInterface |
|
12 | { |
|
13 | ||
14 | /** |
|
15 | * |
|
16 | * @var \Parsedown |
|
17 | */ |
|
18 | private $parser; |
|
19 | ||
20 | public function __construct(array $options = null) |
|
21 | { |
|
22 | $this->parser = new \Parsedown(); |
|
23 | $this->setParserOptions($this->parser, $options); |
|
24 | } |
|
25 | ||
26 | public function transformText($text) |
|
27 | { |
|
28 | return $this->parser->text($text); |
|
29 | } |
|
30 | ||
31 | protected function setParserOptions($parser, $options = null) |
|
32 | { |
|
33 | if (is_array($options)) { |
|
34 | foreach ($options as $key => $value) { |
|
35 | $function = 'set' . ucfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))); |
|
36 | $parser->$function($value); |
|
37 | } |
|
38 | } |
|
39 | } |
|
40 | } |
|
41 |
@@ 11-40 (lines=30) @@ | ||
8 | * @see http://parsedown.org/ |
|
9 | * @author Matthias Glaub <[email protected]> |
|
10 | */ |
|
11 | class ErusevParsedownExtraAdapter implements MarkdownAdapterInterface |
|
12 | { |
|
13 | ||
14 | /** |
|
15 | * |
|
16 | * @var \ParsedownExtra |
|
17 | */ |
|
18 | private $parser; |
|
19 | ||
20 | public function __construct(array $options = null) |
|
21 | { |
|
22 | $this->parser = new \ParsedownExtra(); |
|
23 | $this->setParserOptions($this->parser, $options); |
|
24 | } |
|
25 | ||
26 | public function transformText($text) |
|
27 | { |
|
28 | return $this->parser->text($text); |
|
29 | } |
|
30 | ||
31 | protected function setParserOptions($parser, $options = null) |
|
32 | { |
|
33 | if (is_array($options)) { |
|
34 | foreach ($options as $key => $value) { |
|
35 | $function = 'set' . ucfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))); |
|
36 | $parser->$function($value); |
|
37 | } |
|
38 | } |
|
39 | } |
|
40 | } |
|
41 |