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')] #[Route('/single/{snip}', name: '_single')]
public function single(Snip $snip): Response public function single(Snip $snip): Response
{ {
$snipParser = new Pipeline();
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip); $this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
$snipService = $this->snipServiceFactory->create($snip); $snipService = $this->snipServiceFactory->create($snip);
return $this->render('snip/single.html.twig', [ return $this->render('snip/single.html.twig', [
'snip' => $snip, 'snip' => $snip,
'content' => $snipParser->parse(($snipService->get())), 'content' => (new Pipeline())->parse(($snipService->get())),
'branch' => $snipService->getRepo()->getCurrentBranchName(), 'branch' => $snipService->getRepo()->getCurrentBranchName(),
]); ]);
} }

View File

@ -13,7 +13,8 @@ class Pipeline
$builder = new PipelineBuilder(); $builder = new PipelineBuilder();
$pipeline = $builder $pipeline = $builder
->add(new HtmlEscapeStage()) ->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(); ->build();
return $pipeline->process($payload); return $pipeline->process($payload);

View File

@ -44,5 +44,11 @@
{% block js %} {% block js %}
{{ parent() }} {{ parent() }}
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script> <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 %} {% endblock %}