# text_fragment

URL: https://lbliii.github.io/chirp-ui/api/text_fragment/
Section: api
Description: Text-fragment deep-link helper for chirp-ui citation UI.

Pure-URL, stdlib-only (Chirp-agnostic, like route_tabs / grid_state).
Builds ``#:~:text=`` scroll-to-text-fragment links.

---

> For a complete page index, fetch https://lbliii.github.io/chirp-ui/llms.txt.

Text-fragment deep-link helper for chirp-ui citation UI.

Pure-URL, stdlib-only (Chirp-agnostic, like route_tabs / grid_state).
Builds`#:~:text=`scroll-to-text-fragment links.

text_fragment

Name

Type

Default

Description

`type`

``

—

`qualified_name`

``

—

`element_type`

``

—

`description`

``

—

`source_file`

``

—

`line_number`

``

—

`is_autodoc`

``

—

`autodoc_element`

``

—

`_autodoc_template`

``

—

`_autodoc_url_path`

``

—

`_autodoc_page_type`

``

—

`title`

``

—

`doc_content_hash`

``

—

## Symbols on this page

function
build_text_fragment_url

Return`href` with a text-fragment so the browser scrolls to/highlights `chunk`.

```
>>> build_text_fragment_url("https://x.test/doc", "exact quote")
'https://x.test/doc#:~:text=exact%20quote'
```
No chunk…

Jump to symbol

(#build_text_fragment_url)

build_text_fragment_url

function

```
def build_text_fragment_url(href: str, chunk: str | None = None) -> str
```

Return`href` with a text-fragment so the browser scrolls to/highlights `chunk`.

```
>>> build_text_fragment_url("https://x.test/doc", "exact quote")
'https://x.test/doc#:~:text=exact%20quote'
```
No chunk -> href unchanged. An existing `#fragment`is preserved and the
text directive is appended with the`:~:`delimiter per the spec.
Percent-encodes`-` , `,` and `&`because they are text-directive
syntax characters.

Parameters

Name

Type

Default

Description

`href`

`str`

—

`chunk`

`str | None`

`None`

View source · /home/runner/work/chirp-ui/chirp-ui/site/../src/chirp_ui/text_fragment.py:1
(https://github.com/lbliii/chirp-ui/blob/main//home/runner/work/chirp-ui/chirp-ui/site/../src/chirp_ui/text_fragment.py#L1)
