Allow inlining code blocks with double quotes

This commit is contained in:
Tim 2023-04-07 18:45:43 +02:00
parent 9898bce41a
commit a697f89083
3 changed files with 11 additions and 4 deletions

View File

@ -46,12 +46,12 @@ class SnipController extends AbstractController
#[Route('/single/{snip}', name: '_single')]
public function single(Snip $snip): Response
{
$snipParser = new Pipeline();
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
$snipService = $this->snipServiceFactory->create($snip);
return $this->render('snip/single.html.twig', [
'snip' => $snip,
'content' => $snipParser->parse(($snipService->get())),
'content' => (new Pipeline())->parse(($snipService->get())),
'branch' => $snipService->getRepo()->getCurrentBranchName(),
]);
}

View File

@ -13,7 +13,8 @@ class Pipeline
$builder = new PipelineBuilder();
$pipeline = $builder
->add(new HtmlEscapeStage())
->add(new ReplaceBlocksStage('<pre><code>', '</code></pre>', '```'))
->add(new ReplaceBlocksStage('<pre><code class="hljs">', '</code></pre>', '```'))
->add(new ReplaceBlocksStage('<code class="hljs">', '</code>', '``'))
->build();
return $pipeline->process($payload);

View File

@ -44,5 +44,11 @@
{% block js %}
{{ parent() }}
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<script>
const codeBlocks = document.querySelectorAll('code.hljs');
codeBlocks.forEach((block) => {
hljs.highlightElement(block);
});
</script>
{% endblock %}