Reconstruct HTML link, adjusting the URL for the given language code if needed.
(
link_text: str,
attributes: list[HTMLLinkAttribute],
lang_code: str,
)
| 404 | |
| 405 | |
| 406 | def _construct_html_link( |
| 407 | link_text: str, |
| 408 | attributes: list[HTMLLinkAttribute], |
| 409 | lang_code: str, |
| 410 | ) -> str: |
| 411 | """ |
| 412 | Reconstruct HTML link, adjusting the URL for the given language code if needed. |
| 413 | """ |
| 414 | |
| 415 | attributes_upd: list[HTMLLinkAttribute] = [] |
| 416 | for attribute in attributes: |
| 417 | if attribute["name"] == "href": |
| 418 | original_url = attribute["value"] |
| 419 | url = _add_lang_code_to_url(original_url, lang_code) |
| 420 | attributes_upd.append( |
| 421 | HTMLLinkAttribute(name="href", quote=attribute["quote"], value=url) |
| 422 | ) |
| 423 | else: |
| 424 | attributes_upd.append(attribute) |
| 425 | |
| 426 | attrs_str = " ".join( |
| 427 | f"{attribute['name']}={attribute['quote']}{attribute['value']}{attribute['quote']}" |
| 428 | for attribute in attributes_upd |
| 429 | ) |
| 430 | return f"<a {attrs_str}>{link_text}</a>" |
| 431 | |
| 432 | |
| 433 | def replace_html_links( |
no test coverage detected