Skip to content

Commit 24b9325

Browse files
committed
Don’t add spaces between marks
1 parent d4f75c6 commit 24b9325

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Modifiers/CoreModifiers.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public function bardText($value)
283283
}
284284

285285
$text = '';
286+
286287
while (count($value)) {
287288
$item = array_shift($value);
288289

@@ -291,8 +292,13 @@ public function bardText($value)
291292
}
292293

293294
if ($item['type'] === 'text') {
294-
$text .= ' '.($item['text'] ?? '');
295+
$text .= ($item['text'] ?? '');
296+
}
297+
298+
if ($item['type'] === 'paragraph' && $text !== '') {
299+
$text .= ' ';
295300
}
301+
296302
array_unshift($value, ...($item['content'] ?? []));
297303
}
298304

tests/Modifiers/BardTextTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,34 @@ public function it_skips_nodes_with_no_type()
128128
$this->assertEquals($expected, $this->modify($data));
129129
}
130130

131+
#[Test]
132+
public function it_preserves_text_without_adding_spaces_between_marks()
133+
{
134+
$data = [
135+
[
136+
'type' => 'paragraph',
137+
'content' => [
138+
['type' => 'text', 'text' => 'The "stat" in '],
139+
['type' => 'text', 'marks' => [['type' => 'bold']], 'text' => 'Stat'],
140+
['type' => 'text', 'text' => 'amic stands for "static".'],
141+
],
142+
],
143+
[
144+
// no type
145+
],
146+
[
147+
'type' => 'paragraph',
148+
'content' => [
149+
['type' => 'text', 'text' => 'Another paragraph.'],
150+
],
151+
],
152+
];
153+
154+
$expected = 'The "stat" in Statamic stands for "static". Another paragraph.';
155+
156+
$this->assertEquals($expected, $this->modify($data));
157+
}
158+
131159
public function modify($arr, ...$args)
132160
{
133161
return Modify::value($arr)->bard_text($args)->fetch();

0 commit comments

Comments
 (0)