From e67a485aa919a2b3a295dff65d6651edf8282455 Mon Sep 17 00:00:00 2001 From: Johnny Huynh <27847622+johnnyhuy@users.noreply.github.com> Date: Sat, 4 Jan 2020 19:04:38 +1100 Subject: [PATCH] Added code highlighter --- composer.json | 3 ++- src/UsefulCommonMarkExtension.php | 38 ++++++++++++++++++------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 13001bb..c41dd15 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "php": "^7.1.3", "ext-json": "*", "laravel/framework": "~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0", - "league/commonmark": "^1.1.0" + "league/commonmark": "^1.1.0", + "spatie/commonmark-highlighter": "^2.1" }, "require-dev": { "mockery/mockery": "^1.2", diff --git a/src/UsefulCommonMarkExtension.php b/src/UsefulCommonMarkExtension.php index a885325..84d6f45 100755 --- a/src/UsefulCommonMarkExtension.php +++ b/src/UsefulCommonMarkExtension.php @@ -4,32 +4,36 @@ namespace JohnnyHuy\Laravel; -use Illuminate\Contracts\Container\BindingResolutionException; +use JohnnyHuy\Laravel\Inline\Element\Gist; use Illuminate\Contracts\Container\Container; +use JohnnyHuy\Laravel\Inline\Element\Codepen; +use JohnnyHuy\Laravel\Inline\Element\YouTube; use JohnnyHuy\Laravel\Block\Element\BlockColor; -use JohnnyHuy\Laravel\Block\Element\TextAlignment; use JohnnyHuy\Laravel\Block\Parser\ColorParser; -use JohnnyHuy\Laravel\Block\Parser\TextAlignmentParser; -use JohnnyHuy\Laravel\Block\Renderer\ColorBlockRenderer; -use JohnnyHuy\Laravel\Block\Renderer\TextAlignmentRenderer; -use JohnnyHuy\Laravel\Inline\Element\Codepen; -use JohnnyHuy\Laravel\Inline\Element\Gist; -use JohnnyHuy\Laravel\Inline\Element\InlineColor; +use JohnnyHuy\Laravel\Inline\Parser\GistParser; +use League\CommonMark\Block\Element\FencedCode; use JohnnyHuy\Laravel\Inline\Element\SoundCloud; -use JohnnyHuy\Laravel\Inline\Element\YouTube; -use JohnnyHuy\Laravel\Inline\Parser\CloseColorParser; +use JohnnyHuy\Laravel\Inline\Element\InlineColor; +use League\CommonMark\Block\Element\IndentedCode; +use JohnnyHuy\Laravel\Block\Element\TextAlignment; use JohnnyHuy\Laravel\Inline\Parser\CodepenParser; -use JohnnyHuy\Laravel\Inline\Parser\GistParser; +use JohnnyHuy\Laravel\Inline\Parser\YouTubeParser; +use JohnnyHuy\Laravel\Inline\Renderer\GistRenderer; +use League\CommonMark\Extension\ExtensionInterface; use JohnnyHuy\Laravel\Inline\Parser\OpenColorParser; +use Spatie\CommonMarkHighlighter\FencedCodeRenderer; +use JohnnyHuy\Laravel\Inline\Parser\CloseColorParser; use JohnnyHuy\Laravel\Inline\Parser\SoundCloudParser; -use JohnnyHuy\Laravel\Inline\Parser\YouTubeParser; use JohnnyHuy\Laravel\Inline\Renderer\CodepenRenderer; -use JohnnyHuy\Laravel\Inline\Renderer\ColorInlineRenderer; -use JohnnyHuy\Laravel\Inline\Renderer\GistRenderer; -use JohnnyHuy\Laravel\Inline\Renderer\SoundCloudRenderer; use JohnnyHuy\Laravel\Inline\Renderer\YouTubeRenderer; +use Spatie\CommonMarkHighlighter\IndentedCodeRenderer; +use JohnnyHuy\Laravel\Block\Parser\TextAlignmentParser; use League\CommonMark\ConfigurableEnvironmentInterface; -use League\CommonMark\Extension\ExtensionInterface; +use JohnnyHuy\Laravel\Block\Renderer\ColorBlockRenderer; +use JohnnyHuy\Laravel\Inline\Renderer\SoundCloudRenderer; +use JohnnyHuy\Laravel\Inline\Renderer\ColorInlineRenderer; +use JohnnyHuy\Laravel\Block\Renderer\TextAlignmentRenderer; +use Illuminate\Contracts\Container\BindingResolutionException; /** * This is the useful CommonMark extension class. @@ -92,6 +96,8 @@ public function __construct(Container $container) $this->blockRenderers = [ TextAlignment::class => $container->make(TextAlignmentRenderer::class), BlockColor::class => $container->make(ColorBlockRenderer::class), + FencedCode::class => $container->make(FencedCodeRenderer::class), + IndentedCode::class => $container->make(IndentedCodeRenderer::class), ]; }