Skip to content

Commit

Permalink
Change getText() method
Browse files Browse the repository at this point in the history
Add spaces around the element if it is not inline.
  • Loading branch information
MioVisman committed Dec 23, 2023
1 parent 826010c commit 75e287c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Parserus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,17 @@ public function getText(int $id = 0): string
$bb = $this->bbcodes[$this->data[$id]['tag']];

if (null === $bb['text_handler']) {
return $body;
if (
isset($body[0])
&& 'inline' !== $bb['type']
) {
$before = preg_match('%^\s%su', $body) ? '' : ' ';
$after = preg_match('%\s$%sDu', $body) ? '' : ' ';

return $before . $body . $after;
} else {
return $body;
}
}

$attrs = [];
Expand Down
2 changes: 1 addition & 1 deletion examples/getText.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@

#output:
#
# Position Astronaut Commander Neil A. Armstrong Command Module Pilot Michael Collins Lunar Module Pilot Edwin "Buzz" E. Aldrin, Jr.
# Position Astronaut Commander Neil A. Armstrong Command Module Pilot Michael Collins Lunar Module Pilot Edwin "Buzz" E. Aldrin, Jr.
#My email [email protected]
#[email protected]
#

0 comments on commit 75e287c

Please sign in to comment.