|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DH\Adf\Builder; |
|
6
|
|
|
|
|
7
|
|
|
use DH\Adf\Node\BlockNode; |
|
8
|
|
|
use DH\Adf\Node\Inline\Text; |
|
9
|
|
|
use DH\Adf\Node\Mark\Em; |
|
10
|
|
|
use DH\Adf\Node\Mark\Link; |
|
11
|
|
|
use DH\Adf\Node\Mark\Strike; |
|
12
|
|
|
use DH\Adf\Node\Mark\Strong; |
|
13
|
|
|
use DH\Adf\Node\Mark\Subsup; |
|
14
|
|
|
use DH\Adf\Node\Mark\TextColor; |
|
15
|
|
|
use DH\Adf\Node\Mark\Underline; |
|
16
|
|
|
use DH\Adf\Node\Node; |
|
17
|
|
|
|
|
18
|
|
|
trait TextBuilder |
|
19
|
|
|
{ |
|
20
|
|
|
public function text(string $text): self |
|
21
|
|
|
{ |
|
22
|
|
|
$this->append(new Text($text)); |
|
23
|
|
|
|
|
24
|
|
|
return $this; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function em(string $text): self |
|
28
|
|
|
{ |
|
29
|
|
|
$this->append(new Text($text, new Em())); |
|
30
|
|
|
|
|
31
|
|
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function strong(string $text): self |
|
35
|
|
|
{ |
|
36
|
|
|
$this->append(new Text($text, new Strong())); |
|
37
|
|
|
|
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function underline(string $text): self |
|
42
|
|
|
{ |
|
43
|
|
|
$this->append(new Text($text, new Underline())); |
|
44
|
|
|
|
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function strike(string $text): self |
|
49
|
|
|
{ |
|
50
|
|
|
$this->append(new Text($text, new Strike())); |
|
51
|
|
|
|
|
52
|
|
|
return $this; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function sub(string $text): self |
|
56
|
|
|
{ |
|
57
|
|
|
$this->append(new Text($text, new Subsup('sub'))); |
|
58
|
|
|
|
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function sup(string $text): self |
|
63
|
|
|
{ |
|
64
|
|
|
$this->append(new Text($text, new Subsup('sup'))); |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function color(string $text, string $color): self |
|
70
|
|
|
{ |
|
71
|
|
|
$this->append(new Text($text, new TextColor($color))); |
|
72
|
|
|
|
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function link(string $text, string $href, ?string $title = null): self |
|
77
|
|
|
{ |
|
78
|
|
|
$this->append(new Text($text, new Link($href, $title))); |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
abstract public function append(Node ...$nodes): BlockNode; |
|
84
|
|
|
} |
|
85
|
|
|
|