On remplace les oembed par des liens

Fix #381
This commit is contained in:
Jean-Marie Favreau 2025-03-21 19:34:24 +01:00
parent 1d97e83ea2
commit e79b310814
2 changed files with 16 additions and 1 deletions

View File

@ -60,7 +60,7 @@
</li>
</ul>
</header>
<div>{{ object.message | safe }}</div>
<div>{{ object.message | remove_oembed | safe }}</div>
</article>
<article>
{% if object.message_type == "from_contributor" or object.message_type == "from_contrib_no_msg" %}

View File

@ -13,6 +13,7 @@ from django.templatetags.static import static
from django.urls import reverse_lazy
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from bs4 import BeautifulSoup
register = template.Library()
@ -280,3 +281,17 @@ def navigation_links(filter, category, calendar, current_view):
def per_day(nb, month):
weekday, number_of_days = calendar.monthrange(month.year, month.month)
return "%.1f" % (nb / number_of_days)
@register.filter
def remove_oembed(html):
soup = BeautifulSoup(html, "html.parser")
for f in soup.select("figure.media"):
oe = f.select("oembed")
if len(oe) == 1 and oe[0].has_attr("url"):
a = soup.new_tag("a")
a.attrs["href"] = oe[0].attrs["url"]
a.string = oe[0].attrs["url"]
f.replaceWith(a)
return str(soup)