|
18 | 18 | from formatters.add_pdf_url_to_frontmatter import generate_pdf_url |
19 | 19 | from temporal.apply_temporal import apply_temporal |
20 | 20 | 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) |
21 | 49 |
|
22 | 50 |
|
23 | 51 | 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_ |
195 | 223 | <dd property="eli:preparatory_act" datatype="xsd:string">{html.escape(forarbeten)}</dd>""") |
196 | 224 |
|
197 | 225 | if celex_nummer: |
| 226 | + celex_links = format_celex_as_links(celex_nummer) |
198 | 227 | column1_items.append(f""" |
199 | 228 | <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>""") |
201 | 230 |
|
202 | 231 | if eu_direktiv: |
203 | 232 | column1_items.append(""" |
|
0 commit comments