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

Wrap 'card' description with appropriate HTML tags #4360

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
<div class="full-bleed-xs d-flex flex-1">
<div class="key-item mx-2 mx-md-3 p-3 w-100 d-flex flex-column">
<h5 class="h3-heading mb-2">{{ title }}</h5>
<p>{{ description | richtext }}</p>
{% if description_is_rich_text %}
{{ description|richtext }}
{% else %}
<p>{{ description }}</p>
{% endif %}
<a class="cta-link mb-2" href="{{ link_url }}">{{ link_label }}</a>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions network-api/networkapi/wagtailpages/templatetags/card_tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import template
from bs4 import BeautifulSoup

register = template.Library()

Expand All @@ -9,6 +10,7 @@ def card(image, title, description, link_url, link_label, commitment=None):
'image': image,
'title': title,
'description': description,
'description_is_rich_text': BeautifulSoup(description, 'html.parser').p is not None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is a safe way to check this: where is description coming from? Because rich text could also be <ul>...</ul> etc. so we don't want to hardcode that only things with <p> are rich text.

Copy link
Collaborator Author

@mmmavis mmmavis Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah agreed that this is not very future proof. I only took CTA's subhead into consideration (passed to template tag as description).

subhead = RichTextField(
        features=[
            'bold', 'italic', 'link',
        ],
        blank=True,
    )

Will update PR.

'link_url': link_url,
'link_label': link_label,
'commitment': commitment,
Expand Down