new-bigly-chat/libs/markdown.php
2024-12-07 17:51:05 -05:00

35 lines
1.2 KiB
PHP
Executable file

<?php
function markdown($text) {
$search = array (
'~(https://[^.]+\.dervland\.net/[^\s<]+)~i',
'~(?:\s|^)(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
'~(?:@)([^\s]+)(?:\s|$)~i',
'~(\[b\])(.*?)(\[\/b\])~i',
'~(\[i\])(.*?)(\[\/i\])~i',
'~(\[u\])(.*?)(\[\/u\])~i',
'~(\[ul\])(.*?)(\[\/ul\])~i',
'~(\[li\])(.*?)(\[\/li\])~i',
'~(\[h\])(.*?)(\[\/h\])~i',
'~(\[url=)(.*?)(\])(.*?)(\[\/url\])~i',
'~(\[url\])(.*?)(\[\/url\])~i'
);
$replace = array (
'<a class="link" href="$1" target="_blank"><img src="$1" class="img"></a>',
'<a class="link" href="$0" target="_blank">$0</a>',
'<a class="link" href="/user.php?id=$1" target="_blank">@$1</a>',
'<strong>$2</strong>',
'<em>$2</em>',
'<u>$2</u>',
'<ul>$2</ul>',
'<li>$2</li>',
'<h2>$2</h2>',
'<a class="link" href="$2" target="_blank">$4</a>',
'<a class="link" href="$2" target="_blank">$2</a>'
);
$text = preg_replace($search, $replace, $text);
return $text;
}
?>