Home / Function/ replace_header_permalinks() — fastapi Function Reference

replace_header_permalinks() — fastapi Function Reference

Architecture documentation for the replace_header_permalinks() function in doc_parsing_utils.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  c84f4e4d_0e51_e56e_f03b_1fdd4e46b8f2["replace_header_permalinks()"]
  c463d6a9_085f_f272_b9fc_455b7e9b6a57["doc_parsing_utils.py"]
  c84f4e4d_0e51_e56e_f03b_1fdd4e46b8f2 -->|defined in| c463d6a9_085f_f272_b9fc_455b7e9b6a57
  63822d7d_03fc_4331_3f93_3026c9c03415["check_translation()"]
  63822d7d_03fc_4331_3f93_3026c9c03415 -->|calls| c84f4e4d_0e51_e56e_f03b_1fdd4e46b8f2
  style c84f4e4d_0e51_e56e_f03b_1fdd4e46b8f2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

scripts/doc_parsing_utils.py lines 209–245

def replace_header_permalinks(
    text: list[str],
    header_permalinks: list[HeaderPermalinkInfo],
    original_header_permalinks: list[HeaderPermalinkInfo],
) -> list[str]:
    """
    Replace permalinks in the given text with the permalinks from the original document.

    Fail if the number or level of headers does not match the original.
    """

    modified_text: list[str] = text.copy()

    if len(header_permalinks) != len(original_header_permalinks):
        raise ValueError(
            "Number of headers with permalinks does not match the number in the "
            "original document "
            f"({len(header_permalinks)} vs {len(original_header_permalinks)})"
        )

    for header_no in range(len(header_permalinks)):
        header_info = header_permalinks[header_no]
        original_header_info = original_header_permalinks[header_no]

        if header_info["hashes"] != original_header_info["hashes"]:
            raise ValueError(
                "Header levels do not match between document and original document"
                f" (found {header_info['hashes']}, expected {original_header_info['hashes']})"
                f" for header №{header_no + 1} in line {header_info['line_no']}"
            )
        line_no = header_info["line_no"] - 1
        hashes = header_info["hashes"]
        title = header_info["title"]
        permalink = original_header_info["permalink"]
        modified_text[line_no] = f"{hashes} {title}{permalink}"

    return modified_text

Domain

Subdomains

Frequently Asked Questions

What does replace_header_permalinks() do?
replace_header_permalinks() is a function in the fastapi codebase, defined in scripts/doc_parsing_utils.py.
Where is replace_header_permalinks() defined?
replace_header_permalinks() is defined in scripts/doc_parsing_utils.py at line 209.
What calls replace_header_permalinks()?
replace_header_permalinks() is called by 1 function(s): check_translation.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free