Skip to content

Commit b78972c

Browse files
authored
Merge pull request #63 from zorexsalvo/feat/btn-marker-links
Feat/btn marker links
2 parents df65943 + dc0ca34 commit b78972c

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

app/pages/templates/pages/detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "base.html" %}
2-
{% load static %}
2+
{% load static content_filters %}
33
{% block content %}
44
<main>
55
<div class="min-h-screen bg-contain bg-center" style="background-image: url('{% static 'img/bg-conference-at-glance.png' %}');">
@@ -10,7 +10,7 @@
1010
<article>
1111
<h1 class="text-5xl my-10 font-bold font-td_pinoy text-orange-2 hyphens-auto">{{ page.title|safe }}</h1>
1212
<div class="prose prose-lg max-w-none prose-custom">
13-
{{ page.content|safe }}
13+
{{ page.content|render_buttons }}
1414
</div>
1515
</article>
1616
</div>

app/pages/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import re
2+
3+
from django import template
4+
from django.utils.html import mark_safe
5+
6+
register = template.Library()
7+
8+
9+
def _replace_btn_link(match):
10+
attrs = match.group(1)
11+
text = match.group(2)
12+
13+
if "|btn" not in text:
14+
return match.group(0)
15+
16+
clean_text = text.replace("|btn", "").strip()
17+
18+
if "class=" in attrs:
19+
attrs = re.sub(r'class=["\']([^"\']*)["\']', r'class="\1 btn btn-primary"', attrs)
20+
else:
21+
attrs += ' class="btn btn-primary"'
22+
23+
return f"<a {attrs}>{clean_text}</a>"
24+
25+
26+
@register.filter
27+
def render_buttons(value):
28+
"""Convert links with |btn marker in their text to button-styled links.
29+
30+
Usage in TinyMCE: set link text to "Click here|btn"
31+
Output: <a href="..." class="btn btn-primary">Click here</a>
32+
"""
33+
result = re.sub(r"<a\s+([^>]+)>([^<]*\|btn[^<]*)</a>", _replace_btn_link, value)
34+
return mark_safe(result)

templates/includes/announcement_modal.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Announcement modal component. Displays the latest published announcement from the database.
33
The modal is dismissible and won't show again until browser session is closed or cache is cleared.
44
{% endcomment %}
5+
{% load content_filters %}
56

67
{% if latest_announcement %}
78
<dialog id="announcement-modal" class="modal" open>
@@ -11,7 +12,7 @@
1112
</form>
1213
<h3 class="font-bold text-2xl mb-4">📢 {{ latest_announcement.title }}</h3>
1314
<div class="py-4 prose prose-sm max-w-none [&_p]:text-lg [&_p]:pb-4 [&_h1]:text-lg [&_h2]:text-xl">
14-
{{ latest_announcement.content|safe }}
15+
{{ latest_announcement.content|render_buttons }}
1516
</div>
1617
</div>
1718
<form method="dialog" class="modal-backdrop">

0 commit comments

Comments
 (0)