[pre] blocks now preserve spaces

- Added test case
- Added English documentation
This commit is contained in:
Hypolite Petovan 2020-06-23 07:53:18 -04:00
parent 251a3791dd
commit faeffff8a3
3 changed files with 17 additions and 1 deletions

View file

@ -633,6 +633,14 @@ On Mastodon this field is used for the content warning.
</td> </td>
<td>@user@domain.tld #hashtag</td> <td>@user@domain.tld #hashtag</td>
</tr> </tr>
<tr>
<td>Additionally, [pre] blocks preserve spaces:
<ul>
<li>[pre]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Spaces[/pre]</li>
</ul>
</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Spaces</td>
</tr>
<tr> <tr>
<td>[nosmile] is used to disable smilies on a post by post basis<br> <td>[nosmile] is used to disable smilies on a post by post basis<br>
<br> <br>

View file

@ -1878,7 +1878,11 @@ class BBCode
// Remove escaping tags // Remove escaping tags
$text = preg_replace("/\[noparse\](.*?)\[\/noparse\]/ism", '\1', $text); $text = preg_replace("/\[noparse\](.*?)\[\/noparse\]/ism", '\1', $text);
$text = preg_replace("/\[nobb\](.*?)\[\/nobb\]/ism", '\1', $text); $text = preg_replace("/\[nobb\](.*?)\[\/nobb\]/ism", '\1', $text);
$text = preg_replace("/\[pre\](.*?)\[\/pre\]/ism", '\1', $text);
// Additionally, [pre] tags preserve spaces
$text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", function ($match) {
return str_replace(' ', '&nbsp;', $match[1]);
}, $text);
return $text; return $text;
}); // Escaped code }); // Escaped code

View file

@ -241,6 +241,10 @@ class BBCodeTest extends MockedTest
'expectedHtml' => '[test] Space', 'expectedHtml' => '[test] Space',
'text' => '[test] Space', 'text' => '[test] Space',
], ],
'task-8800-pre-spaces' => [
'expectedHtml' => '&nbsp;&nbsp;&nbsp;&nbsp;Spaces',
'text' => '[pre] Spaces[/pre]',
],
]; ];
} }