Skip to content

Commit 2f5558a

Browse files
iandunndd32
andcommitted
Preserve Newlines & nested lists.
This preserves newlines within docblocks after end-of-sentence and before-list-items, so that the lists can be parsed more efficiently. Fixes WordPress/wporg-developer#45 Merdeg from fork WordPress/wporg-developer#49 Co-Authored-By: Dion Hulse <[email protected]>
1 parent 7ae98fc commit 2f5558a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/runner.php

+17
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ function ( $matches ) use ( $replacement_string ) {
161161
$text
162162
);
163163

164+
// Insert a newline when \n follows `.`.
165+
$text = preg_replace(
166+
"/\.[\n\r]+(?!\s*[\n\r])/m",
167+
'.<br>',
168+
$text
169+
);
170+
171+
// Insert a new line when \n is followed by what appears to be a list.
172+
$text = preg_replace(
173+
"/[\n\r]+(\s+[*-] )(?!\s*[\n\r])/m",
174+
'<br>$1',
175+
$text
176+
);
177+
164178
// Merge consecutive non-blank lines together by replacing the newlines with a space.
165179
$text = preg_replace(
166180
"/[\n\r](?!\s*[\n\r])/m",
@@ -406,5 +420,8 @@ function format_description( $description ) {
406420
$parsedown = \Parsedown::instance();
407421
$description = $parsedown->line( $description );
408422
}
423+
424+
$description = fix_newlines( $description );
425+
409426
return $description;
410427
}

0 commit comments

Comments
 (0)