support markdown links; strip markdown image urls; trim leading blank lines; support markdown multiline comments that include highlight tag
This commit is contained in:
parent
428303c9fb
commit
52f90c5673
@ -92,13 +92,11 @@ class CProject {
|
||||
$this->longdesc
|
||||
);
|
||||
|
||||
// Extract short description
|
||||
$parts = explode("\n", $this->longdesc);
|
||||
$this->shortdesc = array_shift($parts);
|
||||
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
|
||||
|
||||
// Filters for longdesc
|
||||
// Strip out any markdown image links
|
||||
// [![](doc/image1.thumb.png)](doc/image1.png)
|
||||
$this->longdesc = preg_replace('~\\[!.+?\\)\\]\\(.+?\\)~m', '', $this->longdesc);
|
||||
|
||||
// Find "Written in" tags
|
||||
$this->prefix_html = '';
|
||||
$this->longdesc = preg_replace_callback('~\nWritten in ([^\\n]+)~ms', function($matches) {
|
||||
$this->prefix_html .= (
|
||||
@ -118,11 +116,18 @@ class CProject {
|
||||
return '';
|
||||
}, $this->longdesc);
|
||||
|
||||
// Collapse multiple blank lines
|
||||
$this->longdesc = ltrim($this->longdesc, "\n");
|
||||
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")."\n";
|
||||
|
||||
// Extract short description (last)
|
||||
$parts = explode("\n", $this->longdesc);
|
||||
$this->shortdesc = array_shift($parts);
|
||||
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
11
lib/util.php
11
lib/util.php
@ -148,12 +148,19 @@ function text2html($sz) {
|
||||
|
||||
$base = preg_replace('~^=+(.+)=+~m', '<strong>\\1</strong>', $base);
|
||||
$base = preg_replace('~\\[url=([^\\]]+?)\\](.+?)\\[/url\\]~m', '<a href="\\1">\\2</a>', $base);
|
||||
$base = preg_replace('~([^="])(https?://[^ \\r\\n\\t]+)~i', '\\1<a href="\\2">\\2</a>', $base);
|
||||
|
||||
$base = preg_replace('~\\[([^\\]]+?)\\]\\((https?://.+?)\\)~m', '<a href="\\2">\\1</a>', $base); // Support markdown-style URLs
|
||||
|
||||
$base = preg_replace('~([^="])(https?://[^ \\r\\n\\t]+)~i', '\\1<a href="\\2">\\2</a>', $base); // Support standalone URLs
|
||||
$base = preg_replace('~\\[b\\](.+?)\\[/b\\]~m', '<strong>\\1</strong>', $base);
|
||||
$base = preg_replace('~\\[i\\](.+?)\\[/i\\]~m', '<i>\\1</i>', $base);
|
||||
$base = preg_replace('~\\[spoiler\\](.+?)\\[/spoiler\\]~m', '<span class="spoiler">\\1</span>', $base);
|
||||
$base = preg_replace('~\n- ~ms', "\n• ", $base);
|
||||
|
||||
$base = preg_replace('~^```.+$~m', '`', $base); // Convert ```html to single `{}` element
|
||||
|
||||
// TODO support markdown tables
|
||||
|
||||
$btparts = explode('`', $base);
|
||||
if (count($btparts) > 1 && (count($btparts) % 2)) {
|
||||
for ($i = 1, $e = count($btparts); $i < $e; $i += 2) {
|
||||
@ -161,7 +168,7 @@ function text2html($sz) {
|
||||
if (strpos($btparts[$i], "\n") !== false) {
|
||||
$class .= ' code-multiline';
|
||||
}
|
||||
$btparts[$i] = '<span class="'.$class.'">'.$btparts[$i].'</span>';
|
||||
$btparts[$i] = '<span class="'.$class.'">'.ltrim($btparts[$i], "\n").'</span>';
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user