isReferenceInHeading
Checks if a reference sits inside a heading.
The answer comes from the parsed heading positions of the file’s metadata, never from a pattern over its text: a reference is inside a heading when it is fully contained in a headings entry or in a heading section. The section covers a Setext heading’s underline as well, so both heading syntaxes count.
Only a reference that carries a position within the file’s content can be inside a heading. A FrontmatterLinkCache — a frontmatter link, a multi-link frontmatter value entry, or any canvas reference — never is.
A link in a heading is part of that heading’s text, and so of every #heading subpath pointing at it. Rewriting such a link changes the heading text and breaks those subpaths, which is why a link converter may want to leave it alone.
Import:
import { isReferenceInHeading } from '@mnaoumov/obsidian-lib/reference';Signature:
function isReferenceInHeading(reference: Reference, cache: CachedMetadata | null): booleanParameters:
| Parameter | Type | Description |
|---|---|---|
reference |
Reference | The reference to check. |
cache |
CachedMetadata | null | The metadata of the file the reference belongs to. |
Returns: boolean — Whether the reference is fully contained in a heading.
Links to this page: