Fix Markdown link conversion in parseMarkdown function

- Added regex to convert [text](url) to HTML links
- Added conversion for relative internal links to CMS format
- Links now work properly in blog posts and home page
This commit is contained in:
Edwin Noorlander 2025-11-19 13:49:39 +01:00
parent 0dbe4317e2
commit bd0f6ecbfc

View File

@ -211,6 +211,14 @@ class CodePressCMS {
$body = preg_replace('/# (.+)/', '<h1>$1</h1>', $body);
$body = preg_replace('/\*\*(.+?)\*\*/', '<strong>$1</strong>', $body);
$body = preg_replace('/\*(.+?)\*/', '<em>$1</em>', $body);
// Convert Markdown links to HTML links
$body = preg_replace('/\[([^\]]+)\]\(([^)]+)\)/', '<a href="$2">$1</a>', $body);
// Convert relative internal links to CMS format
$body = preg_replace('/href="\/blog\/([^"]+)"/', 'href="?page=blog/$1"', $body);
$body = preg_replace('/href="\/([^"]+)"/', 'href="?page=$1"', $body);
$body = preg_replace('/\n\n/', '</p><p>', $body);
$body = '<p>' . $body . '</p>';
$body = preg_replace('/<p><\/p>/', '', $body);