Skip to content

Commit 6d0ebf2

Browse files
committed
Fix nbsp handling in Markdown encoder
1 parent 2245391 commit 6d0ebf2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/MarkupKit/Core/String/Encoder/Markdown/MarkdownEncoder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ protected function encodeElement(AbstractAttributedElement $element): string
5454
*/
5555
private function splitTrailingWhitespace(string $text): array
5656
{
57-
if (preg_match('/\s+$/', $text, $matches)) {
57+
// use unicode-aware regex to match trailing whitespace including non-breaking spaces
58+
if (preg_match('/\s+$/u', $text, $matches)) {
5859
$trailingSpaces = $matches[0];
5960
return [substr($text, 0, -strlen($trailingSpaces)), $trailingSpaces];
6061
}

tests/MarkdownEncoderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static function encodingDataProvider(): array
4848
['<img src="image.jpg" alt="Image" title="Title">', '![Image](image.jpg "Title")'],
4949
['<img src="image.jpg" alt="">', '![image](image.jpg)'],
5050
['<img src="image.jpg">', '![image](image.jpg)'],
51+
['<b>More: </b>you can find more information here', '**More:** you can find more information here']
5152
];
5253

5354
return array_combine(

0 commit comments

Comments
 (0)