17 lines
862 B
PHP
17 lines
862 B
PHP
<?php
|
|
class MarkdownParser {
|
|
public static function parse($text) {
|
|
$text = htmlspecialchars($text);
|
|
$text = preg_replace('/>>(\d{6})/', '<a href="#$1" class="reply-link">>>$1</a>', $text);
|
|
$text = preg_replace('/\*\*(.*?)\*\*/', '<strong>$1</strong>', $text);
|
|
$text = preg_replace('/\*(.*?)\*/', '<em>$1</em>', $text);
|
|
$text = preg_replace('/_(.*?)_/', '<u>$1</u>', $text);
|
|
$text = preg_replace('/~~(.*?)~~/', '<del>$1</del>', $text);
|
|
$text = preg_replace('/`(.*?)`/', '<code>$1</code>', $text);
|
|
$text = preg_replace('/\[([^\]]+)\]\(([^)]+)\)/', '<a href="$2" target="_blank">$1</a>', $text);
|
|
$text = preg_replace('/^\* (.+)$/m', '<li>$1</li>', $text);
|
|
$text = preg_replace('/(<li>.*<\/li>)/s', '<ul>$1</ul>', $text);
|
|
$text = nl2br($text);
|
|
return $text;
|
|
}
|
|
}
|