Skip to content

Commit 2245391

Browse files
committed
Improved by giving it a more fluent interface.
1 parent 461e6ee commit 2245391

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## v1.3.2 - 2025-08-25
6+
- Improved `AttributedStringBuilder` by giving it a more fluent interface.
7+
58
## v1.3.1 - 2025-08-24
69
- Improved usability of `AttributedStringBuilder` outside parser context.
710

src/MarkupKit/Core/String/AttributeContainer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function withAttribute(Attribute $attribute): self
4444

4545
/**
4646
* @param class-string<Attribute>|(Attribute&UnitEnum) $attribute
47-
* @return self
4847
*/
4948
public function withoutAttribute(string|Attribute $attribute): self
5049
{

src/MarkupKit/Core/String/AttributedStringBuilder.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,39 @@ private function normalizeTrailingSpace(): array
107107
/**
108108
* @param AttributeContainer|array<int, Attribute> $attributes
109109
*/
110-
public function appendString(string $string, AttributeContainer|array $attributes = []): void
110+
public function appendString(string $string, AttributeContainer|array $attributes = []): self
111111
{
112112
$string = $this->normalizeSpace($string, end($this->elements) ?: null);
113113
if (strlen($string) === 0) {
114-
return;
114+
return $this;
115115
}
116116

117117
$this->elements[] = new AttributedSubstring($string, $attributes);
118+
return $this;
118119
}
119120

120121
/**
121122
* @param AttributeContainer|array<int, Attribute> $attributes
122123
*/
123-
public function appendLineBreak(AttributeContainer|array $attributes = []): void
124+
public function appendLineBreak(AttributeContainer|array $attributes = []): self
124125
{
125126
$this->elements[] = new AttributedSubstring("\n", $attributes);
127+
return $this;
126128
}
127129

128-
public function appendAttachment(Attachment $attachment): void
130+
public function appendAttachment(Attachment $attachment): self
129131
{
130132
if (!$this->trimWhitespaceAroundAttachments) {
131133
$this->elements[] = $attachment;
132-
return;
134+
return $this;
133135
}
134136

135137
$this->elements = [
136138
...$this->normalizeTrailingSpace(),
137139
$attachment
138140
];
141+
142+
return $this;
139143
}
140144

141145
public function isEmpty(): bool

0 commit comments

Comments
 (0)