ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
MarkdownFormattingToHTML.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace 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 }
toHTML()
Returns the converted Markdown with HTML tags.
A transformation is a function from one datatype to another.
This class provides a transformation that converts Markdown formatting to HTML using the CommonMark L...
League CommonMark CommonMarkConverter $converter