mirror of
https://github.com/django-components/django-components.git
synced 2025-09-26 07:29:09 +00:00
fix: Using empty default fill with no whitespace (#673)
This commit is contained in:
parent
fa556d281c
commit
6b3c112968
2 changed files with 29 additions and 1 deletions
|
@ -25,9 +25,11 @@ class BaseNode(Node):
|
|||
self.kwargs = kwargs or RuntimeKwargs({})
|
||||
|
||||
|
||||
# NOTE: We consider Nodes to have content only if they have anything else
|
||||
# beside whitespace and comments.
|
||||
def nodelist_has_content(nodelist: NodeList) -> bool:
|
||||
for node in nodelist:
|
||||
if isinstance(node, TextNode) and node.s.isspace():
|
||||
if isinstance(node, TextNode) and (not node.s or node.s.isspace()):
|
||||
pass
|
||||
elif isinstance(node, CommentNode):
|
||||
pass
|
||||
|
|
|
@ -511,3 +511,29 @@ class MultilineTagsTests(BaseTestCase):
|
|||
Variable: <strong>123</strong>
|
||||
"""
|
||||
self.assertHTMLEqual(rendered, expected)
|
||||
|
||||
|
||||
class NestedTagsTests(BaseTestCase):
|
||||
# See https://github.com/EmilStenstrom/django-components/discussions/671
|
||||
@parametrize_context_behavior(["django", "isolated"])
|
||||
def test_nested_tags(self):
|
||||
@register("test_component")
|
||||
class SimpleComponent(Component):
|
||||
template: types.django_html = """
|
||||
Variable: <strong>{{ var }}</strong>
|
||||
"""
|
||||
|
||||
def get_context_data(self, var):
|
||||
return {
|
||||
"var": var,
|
||||
}
|
||||
|
||||
template: types.django_html = """
|
||||
{% load component_tags %}
|
||||
{% component "test_component" var="{% lorem 1 w %}" %}{% endcomponent %}
|
||||
"""
|
||||
rendered = Template(template).render(Context())
|
||||
expected = """
|
||||
Variable: <strong>lorem</strong>
|
||||
"""
|
||||
self.assertHTMLEqual(rendered, expected)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue