From fc28e8c5c8e9c3bf28280e23b02ee8d46668ba71 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 8 Nov 2015 11:35:43 +1300 Subject: [PATCH] improve newline handling, remove redundant newlines --- rebuild.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rebuild.php b/rebuild.php index 1d38b86..9e40f7d 100644 --- a/rebuild.php +++ b/rebuild.php @@ -213,15 +213,23 @@ class CProject { $this->shortdesc = array_shift($parts); $this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase - // Filter longdesc + // Filter longdesc + $this->longdesc = str_replace("\r", "", $this->longdesc); // filter windows CR + $prefix_html = ''; - $this->longdesc = preg_replace_callback('~\r?\nWritten in ([^\\r\\n]+)~ms', function($matches) use (&$prefix_html) { + $this->longdesc = preg_replace_callback('~\r?\nWritten in ([^\\n]+)~ms', function($matches) use (&$prefix_html) { $prefix_html .= ( (SHIELDS_PREFIX ? mkshield('build', 'success', 'brightgreen').' ' : ''). mkshield('written in', $matches[1], 'blue') ); return ''; }, $this->longdesc); + + while(strpos($this->longdesc, "\n\n\n") !== false) { + $this->longdesc = str_replace("\n\n\n", "\n\n", $this->longdesc); + } + $this->longdesc = rtrim($this->longdesc, "\n"); + $this->prefix_html = $prefix_html; continue;