> ## Documentation Index
> Fetch the complete documentation index at: https://mdxify.zzstoatzz.io/llms.txt
> Use this file to discover all available pages before exploring further.

# source_links

# `mdxify.source_links`

Utilities for generating source code links.

## Functions

### `detect_github_repo_url` <sup><a href="https://github.com/zzstoatzz/mdxify/blob/main/src/mdxify/source_links.py#L9" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
detect_github_repo_url() -> Optional[str]
```

Detect GitHub repository URL from git remote.

### `get_relative_path` <sup><a href="https://github.com/zzstoatzz/mdxify/blob/main/src/mdxify/source_links.py#L41" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
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` <sup><a href="https://github.com/zzstoatzz/mdxify/blob/main/src/mdxify/source_links.py#L76" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
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](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` <sup><a href="https://github.com/zzstoatzz/mdxify/blob/main/src/mdxify/source_links.py#L124" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
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
