new-bigly-chat/libs/markdown.php
2024-12-13 20:57:10 -05:00

39 lines
1.5 KiB
PHP
Executable file

<?php
function markdown($text) {
$search = array (
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(png|jpg|jpeg|gif))~i',
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(mp3|wav))~i',
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(webm|mp4))~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"><div>$1</div><img src="$1" class="img"></a>',
'<a class="link" href="$1" target="_blank"><div>$1</div><audio controls src="$1"></a>',
'<a class="link" href="$1" target="_blank"><div>$1</div><video controls class="img"><source src="$1"/></video></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;
}
?>