Skip to content

v1.3.0

Choose a tag to compare

@witiz witiz released this 08 Apr 06:19
· 138 commits to main since this release

Introducing new feature: Passing children to components

Content can be assigned to component the same way we are doing for Fragments or Elements.
To tell your component where such content needs to be injected when rendering, you need to call the self.render_content() reserved method:

from markupy import Component, tag

class Title(Component):
    def __init__(self, id: str) -> None:
        super().__init__()
        self.id = id

    def render(self) -> View:
        return tag.H1(".title.header", id=self.id)[self.render_content()]

Then to use this component:

>>> str(Title(id="headline")["hello ", tag.I(".star.icon")])

This will render as:

<h1 class="title header" id="headline">
    hello <i class="star icon"></i>
</h1>