-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Add getters for docParser/HtmlRenderer/extensions #46
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,11 @@ | |
|
||
class Environment | ||
{ | ||
/** | ||
* @var ExtensionInterface[] | ||
*/ | ||
protected $extensions; | ||
|
||
/** | ||
* @var BlockParserInterface[] | ||
*/ | ||
|
@@ -218,6 +223,8 @@ public function createInlineParserEngine() | |
*/ | ||
public function addExtension(ExtensionInterface $extension) | ||
{ | ||
$this->extensions[] = $extension; | ||
|
||
// Block parsers | ||
foreach ($extension->getBlockParsers() as $blockParser) { | ||
$this->addBlockParser($blockParser); | ||
|
@@ -244,6 +251,14 @@ public function addExtension(ExtensionInterface $extension) | |
} | ||
} | ||
|
||
/** | ||
* @return ExtensionInterface[] | ||
*/ | ||
public function getExtensions() | ||
{ | ||
return $this->extensions; | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about emulating Twig's methodology of lazy-initing the extensions, which would add this functionality (among other things), but I haven't thought of a compelling use-case for it yet. Can you think of a situation where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed it to effectively unit test — to ensure that the right extension was registered by my package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay that makes sense. |
||
* @return Environment | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,4 +142,12 @@ public function renderBlocks($blocks, $inTightList = false) | |
|
||
return implode($this->options['blockSeparator'], $result); | ||
} | ||
|
||
/** | ||
* @return Environment | ||
*/ | ||
public function getEnvironment() | ||
{ | ||
return $this->environment; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be wrong, but I don't feel there's a valid use case for this. When would something need to obtain the environment from the renderer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, needed the environment to get the extensions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just worried about adding and supporting new public methods solely for testing purposes (no strong use-case otherwise). |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against this change, simply because
CommonMarkConverter
is a stupid-simple convenience wrapper for people who only care about simple conversions of CommonMark.Anyone needing additional functionality can easily init those classes themselves and do whatever they feel like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make it more difficult? Also, makes it easier when you think about extensions and the possibility of a factory.
Why should I have to create an environment, docParser and htmlRenderer, when all I want is to change one thing in the htmlRenderer? Instead use this and
->getHtmlRenderer()
and go from there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's nothing you can really change though - if there was, then I'd be okay with this change.