Implement MarkDown parser and improve AbstractParser
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user