ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Markdown.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
28class 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}
This class currently is a stub only.
Definition: HTML.php:28
This class currently is a stub only.
Definition: PlainText.php:28
__construct(Refinery\String\MarkdownFormattingToHTML $markdown_to_html,)
Definition: Markdown.php:32
toPlainText(Text\Text $text)
Definition: Markdown.php:50
toHTML(Text\Text $text)
Definition: Markdown.php:38
isRawStringCompliant(string $text)
Definition: Markdown.php:68
Refinery Transformation $markdown_to_html_transformation
Definition: Markdown.php:30
Methods in this interface should mostly be called by the according methods on Text instances,...
Definition: Shape.php:35