Add custom image size syntax for Markdown files
Support {:width="300" height="200"} syntax in .md files
to set image dimensions via attributes inside {: :}
This commit is contained in:
@@ -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: {: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] = '<img src="' . $url . '" alt="' . $alt . '" ' . $attrs . '>';
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user