Initialize children in Document.__init__()#209
Merged
frostming merged 2 commits intoOct 15, 2024
Conversation
Owner
|
Because not all block elements, like BlankLine, has children, the class attribute serves more as a type hint. It definitely needs to be clarified. Since you are it, can you help remove the |
Contributor
Author
Done! |
Contributor
Author
|
Are you planning to push a release with this fix? I'm not sure what your release cadence is, just wondering if I should continue monkey-patching my fix locally or just wait for this to go live. Thanks for the merge! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm using Marko to parse a Markdown document, split it into multiple documents according to some headings, and then render each of those sub-documents separately. While in the process of doing this, I discovered a strange behaviour:
Looking at Marko's code, it's because you define and assign
children = []as a class variable onBlockElement, and then rely on each subclass to re-initialize it. But, I guess since Document is meant to be virtual, it doesn't do that. So any manually-constructed Document will share the same instance ofchildren, which I'm sure is not intended.Perhaps what I'm missing is some other way to accomplish the goal of constructing a Document object (which can then be
render()-ed) from a sequence of Nodes (filtered out of another Document), rather than from a string. But I don't think this is currently possible, so the only way to do this is to break the virtual-ness of Document and just initialize one. In which case, something like this PR is required.