File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed
project_styleguide/templates/patterns/pages/home Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 44
55from modelcluster .fields import ParentalKey
66from tbx .core .utils .fields import StreamField
7+ from tbx .core .utils .formatting import (
8+ convert_bold_links_to_pink ,
9+ convert_italic_links_to_purple ,
10+ )
711from tbx .core .utils .models import (
812 ColourThemeMixin ,
913 NavigationFields ,
@@ -162,8 +166,9 @@ def partner_logos(self):
162166 "hero_introduction" ,
163167 heading = "Introduction" ,
164168 help_text = mark_safe (
165- 'Use bold to mark text as <span style="color:#EE5276">pink</span>,'
166- " and use italics to mark text as"
169+ "Use bold to mark links as"
170+ ' <span style="color:#EE5276">pink</span>,'
171+ " and use italics to mark links as"
167172 ' <span style="color:#6F60D0">purple</span>.'
168173 ),
169174 ),
@@ -193,6 +198,9 @@ def partner_logos(self):
193198 def get_context (self , request ):
194199 context = super ().get_context (request )
195200 context ["is_home_page" ] = True
201+ context ["hero_introduction" ] = convert_bold_links_to_pink (
202+ convert_italic_links_to_purple (self .hero_introduction )
203+ )
196204 return context
197205
198206
Original file line number Diff line number Diff line change 1+ from bs4 import BeautifulSoup
2+
3+
4+ def convert_bold_links_to_pink (html_text ):
5+ """Convert <b> tags inside links into <span class="text-coral">."""
6+ soup = BeautifulSoup (html_text , "html.parser" )
7+ for anchor_tag in soup .find_all ("a" ):
8+ for bold_tag in anchor_tag .find_all ("b" ):
9+ tag_content = "" .join ([str (c ) for c in bold_tag .contents ])
10+ html_text = html_text .replace (
11+ str (bold_tag ), f'<span class="text-coral">{ tag_content } </span>'
12+ )
13+ return html_text
14+
15+
16+ def convert_italic_links_to_purple (html_text ):
17+ """Convert <i> tags inside links into <span class="text-nebuline">."""
18+ soup = BeautifulSoup (html_text , "html.parser" )
19+ for anchor_tag in soup .find_all ("a" ):
20+ for italic_tag in anchor_tag .find_all ("i" ):
21+ tag_content = "" .join ([str (c ) for c in italic_tag .contents ])
22+ html_text = html_text .replace (
23+ str (italic_tag ), f'<span class="text-nebuline">{ tag_content } </span>'
24+ )
25+ return html_text
Original file line number Diff line number Diff line change 66 {% include "patterns/molecules/home-page-hero/home-page-hero.html" %}
77
88 < div class ="grid__intro heading heading--six ">
9- {{ page. hero_introduction|richtext }}
9+ {{ hero_introduction|richtext }}
1010 </ div >
1111
1212 < div class ="grid__partners ">
You can’t perform that action at this time.
0 commit comments