From eb8064bfbc9b9b7346566cb4c5cb167e885ab1d8 Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Tue, 21 Jul 2026 13:16:33 +0200 Subject: [PATCH] Add custom image size syntax for Markdown files Support ![alt](url){:width="300" height="200"} syntax in .md files to set image dimensions via attributes inside {: :} --- cms/core/class/CodePressCMS.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cms/core/class/CodePressCMS.php b/cms/core/class/CodePressCMS.php index 557be0e..624d171 100644 --- a/cms/core/class/CodePressCMS.php +++ b/cms/core/class/CodePressCMS.php @@ -564,12 +564,28 @@ class CodePressCMS { $environment->addExtension(new \League\CommonMark\Extension\Table\TableExtension()); $environment->addExtension(new \League\CommonMark\Extension\TaskList\TaskListExtension()); + // Handle custom image size syntax: ![alt](url){:width="300" height="200"} + $imagePlaceholders = []; + $content = preg_replace_callback('/!\[([^\]]*)\]\(([^)]+)\)\{:([^}]+)\}/', function ($m) use (&$imagePlaceholders) { + $index = count($imagePlaceholders); + $alt = htmlspecialchars($m[1], ENT_QUOTES, 'UTF-8'); + $url = htmlspecialchars($m[2], ENT_QUOTES, 'UTF-8'); + $attrs = trim($m[3]); + $imagePlaceholders[$index] = '' . $alt . ''; + return '@@IMG_' . $index . '@@'; + }, $content); + // Create converter $converter = new \League\CommonMark\MarkdownConverter($environment); // Convert to HTML $body = $converter->convert($content)->getContent(); + // Restore custom image tags + foreach ($imagePlaceholders as $index => $imgTag) { + $body = str_replace('@@IMG_' . $index . '@@', $imgTag, $body); + } + // Extract clean filename for title (without language prefix and extension) $filename = basename($actualFilePath); $cleanName = $this->formatDisplayName($filename);