Markdown::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.9666
1
<?php
2
3
4
namespace Riclep\Storyblok\Fields;
5
6
7
use League\CommonMark\Environment\Environment;
8
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
9
use League\CommonMark\Extension\Table\TableExtension;
10
use League\CommonMark\MarkdownConverter;
11
use Riclep\Storyblok\Field;
12
13
class Markdown extends Field
14
{
15
	/**
16
	 * Converts the markdown to HTML when printed
17
	 *
18
	 * @return string
19
	 */
20
	public function __toString(): string
21
	{
22
		$config = [
23
			'html_input' => 'escape',
24
			'allow_unsafe_links' => false,
25
			'max_nesting_level' => 100,
26
		];
27
28
		$environment = new Environment($config);
29
		$environment->addExtension(new CommonMarkCoreExtension());
30
		$environment->addExtension(new TableExtension());
31
32
		$converter = new MarkdownConverter($environment);
33
34
		return (string) $converter->convert($this->content);
35
	}
36
}