Skip to content

Commit 75e287c

Browse files
committed
Change getText() method
Add spaces around the element if it is not inline.
1 parent 826010c commit 75e287c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Parserus.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,17 @@ public function getText(int $id = 0): string
12061206
$bb = $this->bbcodes[$this->data[$id]['tag']];
12071207

12081208
if (null === $bb['text_handler']) {
1209-
return $body;
1209+
if (
1210+
isset($body[0])
1211+
&& 'inline' !== $bb['type']
1212+
) {
1213+
$before = preg_match('%^\s%su', $body) ? '' : ' ';
1214+
$after = preg_match('%\s$%sDu', $body) ? '' : ' ';
1215+
1216+
return $before . $body . $after;
1217+
} else {
1218+
return $body;
1219+
}
12101220
}
12111221

12121222
$attrs = [];

examples/getText.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141
#output:
142142
#
143-
# Position Astronaut Commander Neil A. Armstrong Command Module Pilot Michael Collins Lunar Module Pilot Edwin "Buzz" E. Aldrin, Jr.
143+
# Position Astronaut Commander Neil A. Armstrong Command Module Pilot Michael Collins Lunar Module Pilot Edwin "Buzz" E. Aldrin, Jr.
144144
#My email spam@mail.ru
145145
#superspam@mail.ru
146146
#

0 commit comments

Comments
 (0)