diff --git a/view_html.php b/view_html.php index 9d21d04..cbfa824 100644 --- a/view_html.php +++ b/view_html.php @@ -1,4 +1,7 @@ \n"; + } else { + $fullSrc = $baseUrl . '/' . $src; + $localPath = $directory . '/' . $src; + $fileExists = file_exists($localPath); + $debug = "\n"; + + if (!$fileExists) { + return $debug . "\"$alt\""; + } + } + + return $debug . "\"$alt\""; + }, $text); + // Inline formatting $text = preg_replace('/\*\*(.+?)\*\*/', '$1', $text); $text = preg_replace('/\*(.+?)\*/', '$1', $text); $text = preg_replace('/`(.+?)`/', '$1', $text); - $text = preg_replace('/\[(.+?)\]\((.+?)\)/', '$1', $text); + + // Link parsing (do this after image parsing) + $text = preg_replace('/\[([^\]]+)\]\(([^\)]+)\)/', '$1', $text); // Remove empty paragraphs $text = preg_replace('/

\s*<\/p>/', '', $text); @@ -71,9 +99,10 @@ function parseMarkdown($text) { return $text; } -$parsedContent = parseMarkdown($content); - $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']; ?> @@ -87,6 +116,12 @@ $directUrl = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] +