Skip to content

Commit d5bed4a

Browse files
committed
Removed Laravel container injection and added options to code renderer
1 parent dcf6a87 commit d5bed4a

File tree

1 file changed

+17
-73
lines changed

1 file changed

+17
-73
lines changed

src/UsefulCommonMarkExtension.php

Lines changed: 17 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace JohnnyHuy\Laravel;
66

77
use JohnnyHuy\Laravel\Inline\Element\Gist;
8-
use Illuminate\Contracts\Container\Container;
98
use JohnnyHuy\Laravel\Inline\Element\Codepen;
109
use JohnnyHuy\Laravel\Inline\Element\YouTube;
1110
use JohnnyHuy\Laravel\Block\Element\BlockColor;
@@ -33,7 +32,6 @@
3332
use JohnnyHuy\Laravel\Inline\Renderer\SoundCloudRenderer;
3433
use JohnnyHuy\Laravel\Inline\Renderer\ColorInlineRenderer;
3534
use JohnnyHuy\Laravel\Block\Renderer\TextAlignmentRenderer;
36-
use Illuminate\Contracts\Container\BindingResolutionException;
3735

3836
/**
3937
* This is the useful CommonMark extension class.
@@ -42,86 +40,32 @@
4240
*/
4341
class UsefulCommonMarkExtension implements ExtensionInterface
4442
{
45-
/**
46-
* @var array
47-
*/
48-
public $inlineParsers;
49-
50-
/**
51-
* @var array
52-
*/
53-
public $inlineRenderers;
54-
55-
/**
56-
* @var array
57-
*/
58-
public $blockParsers;
59-
60-
/**
61-
* @var array
62-
*/
63-
public $blockRenderers;
64-
65-
/**
66-
* Create the instances here for Laravel container injection.
67-
* This is needed to allow Laravel to inject dependencies.
68-
*
69-
* @param Container $container
70-
* @throws BindingResolutionException
71-
*/
72-
public function __construct(Container $container)
73-
{
74-
$this->inlineParsers = [
75-
$container->make(GistParser::class),
76-
$container->make(CodepenParser::class),
77-
$container->make(YouTubeParser::class),
78-
$container->make(SoundCloudParser::class),
79-
$container->make(OpenColorParser::class),
80-
$container->make(CloseColorParser::class),
81-
];
82-
83-
$this->inlineRenderers = [
84-
Gist::class => $container->make(GistRenderer::class),
85-
Codepen::class => $container->make(CodepenRenderer::class),
86-
YouTube::class => $container->make(YouTubeRenderer::class),
87-
SoundCloud::class => $container->make(SoundCloudRenderer::class),
88-
InlineColor::class => $container->make(ColorInlineRenderer::class)
89-
];
90-
91-
$this->blockParsers = [
92-
$container->make(TextAlignmentParser::class),
93-
$container->make(ColorParser::class),
94-
];
95-
96-
$this->blockRenderers = [
97-
TextAlignment::class => $container->make(TextAlignmentRenderer::class),
98-
BlockColor::class => $container->make(ColorBlockRenderer::class),
99-
FencedCode::class => $container->make(FencedCodeRenderer::class),
100-
IndentedCode::class => $container->make(IndentedCodeRenderer::class),
101-
];
102-
}
103-
10443
/**
10544
* Register the actual extensions to the framework.
10645
*
10746
* @param ConfigurableEnvironmentInterface $environment
10847
*/
10948
public function register(ConfigurableEnvironmentInterface $environment): void
11049
{
111-
foreach ($this->blockParsers as $blockParser) {
112-
$environment->addBlockParser($blockParser);
113-
}
50+
$environment->addBlockParser(new TextAlignmentParser());
51+
$environment->addBlockParser(new ColorParser());
11452

115-
foreach ($this->inlineParsers as $inlineParser) {
116-
$environment->addInlineParser($inlineParser);
117-
}
53+
$environment->addBlockRenderer(TextAlignment::class, new TextAlignmentRenderer());
54+
$environment->addBlockRenderer(BlockColor::class, new ColorBlockRenderer());
55+
$environment->addBlockRenderer(FencedCode::class, new FencedCodeRenderer(['html', 'php', 'js', 'lua', 'python', 'go']), 10);
56+
$environment->addBlockRenderer(IndentedCode::class, new IndentedCodeRenderer(['html', 'php', 'js', 'lua', 'python', 'go']), 10);
11857

119-
foreach ($this->blockRenderers as $class => $blockRenderer) {
120-
$environment->addBlockRenderer($class, $blockRenderer);
121-
}
58+
$environment->addInlineParser(new GistParser());
59+
$environment->addInlineParser(new CodepenParser());
60+
$environment->addInlineParser(new YouTubeParser());
61+
$environment->addInlineParser(new SoundCloudParser());
62+
$environment->addInlineParser(new OpenColorParser());
63+
$environment->addInlineParser(new CloseColorParser());
12264

123-
foreach ($this->inlineRenderers as $class => $inlineRenderer) {
124-
$environment->addInlineRenderer($class, $inlineRenderer);
125-
}
65+
$environment->addInlineRenderer(Gist::class, new GistRenderer());
66+
$environment->addInlineRenderer(Codepen::class, new CodepenRenderer());
67+
$environment->addInlineRenderer(YouTube::class, new YouTubeRenderer());
68+
$environment->addInlineRenderer(SoundCloud::class, new SoundCloudRenderer());
69+
$environment->addInlineRenderer(InlineColor::class, new ColorInlineRenderer());
12670
}
12771
}

0 commit comments

Comments
 (0)