Skip to content

Commit 9d83750

Browse files
committed
Add Celex numbers as clickable EUR-Lex links
1 parent 3c0121b commit 9d83750

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

exporters/html/html_export.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@
1818
from formatters.add_pdf_url_to_frontmatter import generate_pdf_url
1919
from temporal.apply_temporal import apply_temporal
2020
from exporters.html.styling_constants import get_css_variables
21+
from downloaders.eur_lex_api import generate_eur_lex_url
22+
23+
24+
def format_celex_as_links(celex_numbers: str) -> str:
25+
"""
26+
Convert Celex numbers to clickable EUR-Lex links.
27+
28+
Handles multiple Celex numbers separated by commas or spaces.
29+
30+
Args:
31+
celex_numbers (str): One or more Celex numbers (e.g., "32001L0083, 32004L0027")
32+
33+
Returns:
34+
str: HTML string with clickable links to EUR-Lex
35+
"""
36+
if not celex_numbers:
37+
return ""
38+
39+
# Split by comma and/or whitespace, filter out empty strings
40+
celex_list = [celex.strip() for celex in re.split(r'[,\s]+', celex_numbers) if celex.strip()]
41+
42+
# Convert each Celex number to a link
43+
links = []
44+
for celex in celex_list:
45+
url = generate_eur_lex_url(celex)
46+
links.append(f'<a href="{html.escape(url)}" target="_blank">{html.escape(celex)}</a>')
47+
48+
return ', '.join(links)
2149

2250

2351
def create_html_documents(data: Dict[str, Any], output_path: Path, include_amendments: bool = False) -> None:
@@ -195,9 +223,10 @@ def convert_to_html(data: Dict[str, Any], apply_amendments: bool = False, up_to_
195223
<dd property="eli:preparatory_act" datatype="xsd:string">{html.escape(forarbeten)}</dd>""")
196224

197225
if celex_nummer:
226+
celex_links = format_celex_as_links(celex_nummer)
198227
column1_items.append(f"""
199228
<dt>CELEX:</dt>
200-
<dd property="eli:related_to" resource="{html.escape(celex_nummer)}" datatype="xsd:string">{html.escape(celex_nummer)}</dd>""")
229+
<dd property="eli:related_to" resource="{html.escape(celex_nummer)}" datatype="xsd:string">{celex_links}</dd>""")
201230

202231
if eu_direktiv:
203232
column1_items.append("""

0 commit comments

Comments
 (0)