MCPcopy Create free account
hub / github.com/fastapi/fastapi / _construct_html_link

Function _construct_html_link

scripts/doc_parsing_utils.py:406–430  ·  view source on GitHub ↗

Reconstruct HTML link, adjusting the URL for the given language code if needed.

(
    link_text: str,
    attributes: list[HTMLLinkAttribute],
    lang_code: str,
)

Source from the content-addressed store, hash-verified

404
405
406def _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
433def replace_html_links(

Callers 1

replace_html_linksFunction · 0.85

Calls 2

_add_lang_code_to_urlFunction · 0.85
HTMLLinkAttributeClass · 0.85

Tested by

no test coverage detected