Skip to content
Snippets Groups Projects
Verified Commit c800489a authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Merge branch 'master' of edugit.org:AlekSIS/official/AlekSIS

parents 3260c8af f5c757b8
No related branches found
No related tags found
No related merge requests found
Pipeline #1981 failed
from typing import Any
from django import template
from bs4 import BeautifulSoup
register = template.Library()
@register.filter
def add_class_to_el(value: str, arg: str) -> str:
"""Add a CSS class to every occurence of an element type.
Example: {{ mymodel.myhtmlfield|add_class_to_el:"ul,browser-default"
"""
el, cls = value.split(",")
soup = BeautifulSoup(value, "html.parser")
for el in soup.find_all(el):
el["class"] = el.get("class", "") + f" {cls}"
return str(soup)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment