Skip to main content

mdxify.source_links

Utilities for generating source code links.

Functions

detect_github_repo_url

detect_github_repo_url() -> Optional[str]
Detect GitHub repository URL from git remote.

get_relative_path

get_relative_path(file_path: Path, root_module: str) -> Optional[Path]
Get the relative path from the repository root to the source file. Args:
  • file_path: Absolute path to the source file
  • root_module: The root module name (e.g., ‘prefect’, ‘fastmcp’)
Returns:
  • Relative path from repo root, or None if unable to determine
generate_source_link(repo_url: str, branch: str, file_path: Path, line_number: int, root_module: Optional[str] = None) -> Optional[str]
Generate a GitHub source code link. Args:
  • repo_url: GitHub repository URL (e.g., https://github.com/owner/repo)
  • branch: Git branch name
  • file_path: Path to the source file
  • line_number: Line number in the source file
  • root_module: Root module name for finding relative paths
Returns:
  • GitHub URL to the specific line, or None if unable to generate
add_source_link_to_header(header: str, source_link: Optional[str], link_text: str = '[source]') -> str
Add a source link to a markdown header. Args:
  • header: The markdown header (e.g., ”### function_name”)
  • source_link: The source code URL
  • link_text: Text for the link (default: “[source]”)
Returns:
  • Header with inline source link icon
I