Skip to content
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

Added parent attribute #72

Closed
wants to merge 3 commits into from
Closed

Conversation

vallentin
Copy link
Contributor

Resolves #71.

@coveralls
Copy link

coveralls commented Nov 15, 2018

Coverage Status

Coverage increased (+0.07%) to 93.233% when pulling b13d738 on Vallentin:parent into 846a419 on miyuchina:master.

@vallentin
Copy link
Contributor Author

vallentin commented Nov 15, 2018

Here's a suggestion.

Instead of all the for child in children, it might be beneficial to change __init__ of SpanToken and BlockToken. To allow and instead pass all children via super().

Something like:

class SpanToken:
    ...

    def __init__(self, match, children=None):
        if not self.parse_inner:
            self.content = match.group(self.parse_group)
        if children is not None:
            self.children = children
            for child in self.children:
                child.parent = self

    def __contains__(self, text):
        if hasattr(self, 'children'):
            return any(text in child for child in self.children)
        return text in self.content

What do you think @miyuchina? Is the parent attribute even something you want in the first place?

If you're open to this feature, then I'll happily refactor mistletoe.

@pbodnar
Copy link
Collaborator

pbodnar commented Sep 17, 2021

This looks promising. I totally agree with some refactoring though, so that the logic of setting parent into children is kept just at one place.

@pbodnar
Copy link
Collaborator

pbodnar commented Dec 14, 2023

Hi there, I would like to finally finish this feature after all the years. :) I think now, the simplest thing to do is to make the children attribute a @property with a setter function which would take care of setting the parent to all the children. Now that we've already got the common Token ancestor class, it would mean extending just this class. I will check this out and possibly create a fresh PR...

@pbodnar
Copy link
Collaborator

pbodnar commented Mar 20, 2024

Replaced by #206. Thanks for the initial idea. :)

@pbodnar pbodnar closed this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get parent token
3 participants