-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instantion error using Dependency Injection #224
Comments
There's no need to use a Laravel package to solve this problem, once you understand what's happening it's a pretty easy fix: Injecting and erroring:
Fixed
|
But... was it really necessary to make the library so dependable of a static method? Seems super odd these days, and not only to me: https://twitter.com/afilina/status/688437808252465152 And in the library it's an easy fix too, I did it, but I've not created a PR because it broke some tests enforcing Environment being created without extensions:
|
The For example, some users may only want to use a subset of CommonMark, or they may want to include their own custom extension before the According to @GrahamCampbell's Laravel package, you should be able to easily instantiate the $app->singleton('markdown.environment', function ($app) {
return $environment; Environment::createCommonMarkEnvironment();
});
$app->alias('markdown.environment', Environment::class); Could you try that and see if it works for you? If not, could you please provide a code example of what you're trying so I can better understand the situation? |
@antonioribeiro your fix breaks the whole idea of dependency injection. |
@fesor, that fix was implementend on my own Markdown converter, wich uses commonmark, I don't really need it to be injected in this case, that's why it was so easy to fix, sorry if I confused you by not pasting the whole code. @colinodell, as I just said, I don't really need dependency injection to work, my use case is too simple and I was only using it because Laravel makes it easy, but, yes, I'm pretty I'm sure binding it to a closure, to correctly instantiate it, is something that will work. The whole problem started because Commonmark broke on me after a
Of course my first thought was "gosh, what I did wrong here?", and started to hunt down a bug I was not supposed to see, because, in my opinion, if you are making a change to So I went to try to fix instantiation, rewriting some stuff, and got some tests on red because some people really need Environment to be empty, sometimes... |
From what I can tell, the We do follow Semantic Versioning, so as long as you're using the proper version constraints in The error you encountered is a legitimate issue which seems to be caused when parsing text without having any inline parsers declared. I'll work on a solution for this issue now. |
If an Environment creates without any inline parsers, the `getInlineParserCharacterRegex()` method will return an invalid regular expression. This fix ensures that a valid regex is returned in this particular edge case.
If an Environment creates without any inline parsers, the `getInlineParserCharacterRegex()` method will return an invalid regular expression. This fix ensures that a valid regex is returned in this particular edge case. Conflicts: tests/unit/EnvironmentTest.php
If an Environment creates without any inline parsers, the `getInlineParserCharacterRegex()` method will return an invalid regular expression. This fix ensures that a valid regex is returned in this particular edge case.
I disagree that this is a bug. Nothing needs changing IMO. |
Fix empty inline character regex (#224)
I agree that the instantiation question is probably not a bug, but the $environment = new Environment();
$environment->addBlockRenderer(Document::class, new DocumentRenderer());
$environment->addBlockRenderer(Paragraph::class, new ParagraphRenderer());
$environment->addInlineRenderer(Text::class, new TextRenderer());
$converter = new CommonMarkConverter([], $environment);
echo $converter->convertToHtml('Hello World!'); This will echo out @antonioribeiro if you can provide some sample code of instantiating failing I'd be happy to take a closer look. Otherwise I'm going to close this report since the underlying issue should be resolved. |
If you use something like Laravel, which recursively instantiates all the things, you get an error, because Environment is only correctly instantiable if we use the static method createCommonMarkEnvironment to boot it up.
The text was updated successfully, but these errors were encountered: