Allow inlining code blocks with double quotes
This commit is contained in:
parent
9898bce41a
commit
a697f89083
@ -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(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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 %}
|
Loading…
Reference in New Issue
Block a user