" . trim($matches[2]) . ""; } // List items elseif (preg_match('/^(\s*[-*+])\s+(.+)$/', $line, $matches)) { if (!$inList) { $inList = true; $listBuffer[] = "
" . $line . "
"; } // Empty lines else { $parsed[] = ""; } } // Close any open list if ($inList) { $listBuffer[] = ""; $parsed = array_merge($parsed, $listBuffer); } $text = implode("\n", $parsed); // Inline formatting $text = preg_replace('/\*\*(.+?)\*\*/', '$1', $text); $text = preg_replace('/\*(.+?)\*/', '$1', $text); $text = preg_replace('/`(.+?)`/', '$1', $text);
$text = preg_replace('/\[(.+?)\]\((.+?)\)/', '$1', $text);
// Remove empty paragraphs
$text = preg_replace('/\s*<\/p>/', '', $text); return $text; } $parsedContent = parseMarkdown($content); $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $directUrl = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>