From 0f7e4ccc07f05e4881dcde9290f7bb5e6781a0a3 Mon Sep 17 00:00:00 2001
From: Edwin Noorlander
', $body); $body = '
' . $body . '
'; $body = preg_replace('/<\/p>/', '', $body); @@ -234,22 +234,36 @@ class CodePressCMS { ]; } - private function autoLinkPageTitles($content) { +private function autoLinkPageTitles($content) { // Get all available pages with their titles $pages = $this->getAllPageTitles(); foreach ($pages as $pagePath => $pageTitle) { // Create a pattern that matches the exact page title (case-insensitive) + // Use word boundaries to avoid partial matches $pattern = '/\b' . preg_quote($pageTitle, '/') . '\b/i'; - // Replace with link, but avoid linking inside existing links or headings + // Replace with link, but avoid linking inside existing links, headings, or markdown $replacement = function($matches) use ($pageTitle, $pagePath) { - // Check if we're inside an HTML tag or link - $before = substr($matches[0], 0, 50); - if (preg_match('/<[^>]*$/', $before) || preg_match('/href=/', $before)) { - return $matches[0]; // Don't link inside HTML tags + $text = $matches[0]; + + // Check if we're inside an existing link or markdown syntax + if (preg_match('/\[.*?\]\(.*?\)/', $text) || + preg_match('/\[.*?\]:/', $text) || + preg_match('/]*>/', $text) || + preg_match('/href=/', $text)) { + return $text; // Don't link existing links } + return '' . $text . ''; + }; + + $content = preg_replace_callback($pattern, $replacement, $content); + } + + return $content; + } + return '' . $matches[0] . ''; }; diff --git a/templates/layout.html b/templates/layout.html index 5e99457..6a24deb 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -165,13 +165,15 @@ .auto-link { color: #0d6efd; text-decoration: none; - border-bottom: 1px dotted #0d6efd; + border-bottom: 2px dashed #0d6efd; font-weight: 500; + transition: all 0.2s ease; } .auto-link:hover { color: #0a58ca; text-decoration: none; border-bottom-style: solid; + border-bottom-color: #0a58ca; } .search-form { max-width: 300px;