Implement MarkDown parser and improve AbstractParser

This commit is contained in:
Tim
2025-04-23 21:50:50 +02:00
parent cc3e050304
commit 0f6cc78e5e
9 changed files with 477 additions and 32 deletions

View File

@@ -13,24 +13,16 @@ class TwigParser extends AbstractParser
private readonly SnipLoader $snipLoader,
) {}
public static function getName(): string
public function safeParseView(string $content): string
{
return 'twig';
}
$loader = new ChainLoader([
new ArrayLoader([
'index' => $content,
]),
$this->snipLoader,
]);
$twig = new Environment($loader);
public function parseView(string $content): string
{
try {
$loader = new ChainLoader([
new ArrayLoader([
'index' => $content,
]),
$this->snipLoader,
]);
$twig = new Environment($loader);
return $twig->render('index');
} catch (\Exception $exception) {
return sprintf('<pre><code class="hljs">%s</code></pre>', htmlspecialchars($exception->getMessage()));
}
return $twig->render('index');
}
}