ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MarkdownFormattingToHTML.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Refinery\String;
22
24
29{
30 private \League\CommonMark\CommonMarkConverter $converter;
31
32 public function __construct(bool $escape = true)
33 {
34 $config = [
35 'allow_unsafe_links' => false,
36 'max_nesting_level' => 42 // https://commonmark.thephpleague.com/1.5/security/#nesting-level
37 ];
38
39 if ($escape === true) {
40 $config['html_input'] = 'escape';
41 }
42
43 $this->converter = new \League\CommonMark\CommonMarkConverter($config);
44 }
45
49 public function toHTML(): Transformation
50 {
51 return new \ILIAS\Refinery\Custom\Transformation(
52 fn($value) => $this->converter->convert($value)->getContent()
53 );
54 }
55}
This class provides a transformation that converts Markdown formatting to HTML using the CommonMark L...
toHTML()
Returns the converted Markdown with HTML tags.
League CommonMark CommonMarkConverter $converter
A transformation is a function from one datatype to another.