ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Markdown.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use ILIAS\Data\Text;
26 use ILIAS\Refinery;
27 
28 class Markdown implements Shape
29 {
30  protected Refinery\Transformation $markdown_to_html_transformation;
31 
32  public function __construct(
33  Refinery\String\MarkdownFormattingToHTML $markdown_to_html,
34  ) {
35  $this->markdown_to_html_transformation = $markdown_to_html->toHTML();
36  }
37 
38  public function toHTML(Text\Text $text): Text\HTML
39  {
40  if (!$text instanceof Text\Markdown) {
41  throw new \LogicException("Text does not match format.");
42  }
43  return new Text\HTML(
44  $this->markdown_to_html_transformation->transform(
45  $text->getRawRepresentation()
46  )
47  );
48  }
49 
50  public function toPlainText(Text\Text $text): Text\PlainText
51  {
52  if (!$text instanceof Text\Markdown) {
53  throw new \LogicException("Text does not match format.");
54  }
55  return new Text\PlainText($text->getRawRepresentation());
56  }
57 
58  public function getMarkup(): Markup\Markdown
59  {
60  return new Markup\Markdown();
61  }
62 
63  public function fromString(string $text): Text\Markdown
64  {
65  return new Text\Markdown($this, $text);
66  }
67 
68  public function isRawStringCompliant(string $text): bool
69  {
70  return true;
71  }
72 }
Methods in this interface should mostly be called by the according methods on Text instances...
Definition: Shape.php:34
toPlainText(Text\Text $text)
Definition: Markdown.php:50
This class currently is a stub only.
Definition: PlainText.php:27
toHTML(Text\Text $text)
Definition: Markdown.php:38
This class currently is a stub only.
Definition: HTML.php:27
__construct(Refinery\String\MarkdownFormattingToHTML $markdown_to_html,)
Definition: Markdown.php:32
isRawStringCompliant(string $text)
Definition: Markdown.php:68
Refinery Transformation $markdown_to_html_transformation
Definition: Markdown.php:30