" . 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); // Image parsing (do this before link parsing) $text = preg_replace_callback('/!\[([^\]]*)\]\(([^\)]+)\)/', function($matches) use ($baseUrl, $directory) { $alt = $matches[1]; $src = $matches[2]; $isExternal = preg_match('/^https?:\/\//', $src); if ($isExternal) { $fullSrc = $src; $debug = "\n"; } else { $fullSrc = $baseUrl . '/' . $src; $localPath = $directory . '/' . $src; $fileExists = file_exists($localPath); $debug = "\n"; if (!$fileExists) { return $debug . "$1', $text);
// Link parsing (do this after image parsing)
$text = preg_replace('/\[([^\]]+)\]\(([^\)]+)\)/', '$1', $text);
// Remove empty paragraphs
$text = preg_replace('/\s*<\/p>/', '', $text); return $text; } $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $baseUrl = $protocol . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); $parsedContent = parseMarkdown($content, $baseUrl, $directory); $directUrl = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>