Dokumentation nicht gefunden.
';
}
$markdown = file_get_contents($mdPath);
$environment = new Environment([
'html_input' => 'allow',
'allow_unsafe_links' => false,
]);
$environment->addExtension(new CommonMarkCoreExtension);
$environment->addExtension(new GithubFlavoredMarkdownExtension);
$converter = new MarkdownConverter($environment);
return $converter->convert($markdown)->getContent();
}
/**
* @return list
*/
public static function tableOfContents(): array
{
$mdPath = self::markdownPath();
if (! file_exists($mdPath)) {
return [];
}
$markdown = file_get_contents($mdPath);
$toc = [];
preg_match_all('/^(#{2,3})\s+(.+)$/m', $markdown, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$level = strlen($match[1]);
$title = trim($match[2]);
$slug = Str::slug($title);
$toc[] = [
'level' => $level,
'title' => $title,
'slug' => $slug,
];
}
return $toc;
}
/**
* @return array{size: string, modified: string, lines: int}|null
*/
public static function fileInfo(): ?array
{
$mdPath = self::markdownPath();
if (! file_exists($mdPath)) {
return null;
}
return [
'size' => round(filesize($mdPath) / 1024, 1).' KB',
'modified' => Carbon::parse(filemtime($mdPath))->format('d.m.Y H:i'),
'lines' => count(file($mdPath)),
];
}
}