Skip to content

Commit eb0a8bd

Browse files
authored
Merge pull request #55 from toolstack/whitespace-fix
Fix duplicate line generation in whitespace code.
2 parents cf04dc0 + b6b654f commit eb0a8bd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

includes/class-mastodon-api.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,9 +1018,14 @@ private function get_user_id_from_request( $request ) {
10181018
* @return string The normalized content.
10191019
*/
10201020
private function normalize_whitespace( $post_content ) {
1021-
$post_content = preg_replace( '#<!-- /?wp:paragraph -->\s*<!-- /?wp:paragraph -->#', PHP_EOL, $post_content );
1022-
$post_content = preg_replace( '#\n\s*\n+#', PHP_EOL, $post_content );
1023-
$post_content = str_replace( '&#039;', "'", $post_content );
1021+
// First remove any Gutenberg tags with whitespace between them.
1022+
$post_content = preg_replace( '#<!-- /?wp:paragraph -->\s*<!-- /?wp:paragraph -->#', '', $post_content );
1023+
// Then remove *all* remaining Gutenberg tags.
1024+
$post_content = preg_replace( '#<!-- /?wp:[a-zA-Z]+? -->#', '', $post_content );
1025+
// Now remove any line breaks with whitespaces between them.
1026+
$post_content = preg_replace( '#' . PHP_EOL . '\s*' . PHP_EOL . '+#', '', $post_content );
1027+
// Finally remove all remaining line breaks.
1028+
$post_content = str_replace( PHP_EOL, '', $post_content );
10241029

10251030
return trim( $post_content );
10261031
}

0 commit comments

Comments
 (0)