calternal_notes_core::links
Markdown reference scanning and byte-scoped link edits.
The scanner records destination byte ranges instead of serializing Markdown. Rename writes can therefore change a path while preserving labels, spacing, escaping, line endings, and all prose around the link. Reference definitions and URL-encoded destinations use the same identity-preserving move scanner (#618 independent review; DESIGN §§33, 40).
Source: crates/calternal-notes-core/src/links.rs
Structs
Section titled “Structs”LinkReference
Section titled “LinkReference”pub struct LinkReferenceNo doc comment.
Fields
pub target: String: Decoded logical target (without<...>wrappers).pub raw_target: String: Source spelling inside the destination delimiters.pub destination: Range<usize>: Destination bytes only. Edits must replace this range, never the link label.pub kind: LinkKindpub alias: Option<String>
Implements: Debug, Clone, PartialEq, Eq
Source: crates/calternal-notes-core/src/links.rs:38
NoteFeatures
Section titled “NoteFeatures”pub struct NoteFeaturesNo doc comment.
Fields
pub links: Vec<LinkReference>pub embeds: Vec<LinkReference>pub tags: Vec<String>pub block_ids: Vec<String>
Implements: Debug, Clone, Default, PartialEq, Eq
Source: crates/calternal-notes-core/src/links.rs:53
NoteTarget
Section titled “NoteTarget”pub struct NoteTargetNo doc comment.
Fields
pub path: Stringpub title: String
Implements: Debug, Clone, PartialEq, Eq
Source: crates/calternal-notes-core/src/links.rs:70
TagReference
Section titled “TagReference”pub struct TagReferenceNo doc comment.
Fields
pub value: Stringpub span: Range<usize>: The complete source token, including one or two leading#bytes.pub literal: bool:##tagis an explicit literal namespace escape in the composer.
Implements: Debug, Clone, PartialEq, Eq
Source: crates/calternal-notes-core/src/links.rs:61
UnresolvedWikilink
Section titled “UnresolvedWikilink”pub struct UnresolvedWikilinkA wikilink that the resolver cannot safely turn into a Home link.
Fields
pub source: Stringpub line: usizepub ambiguous: bool
Implements: Debug, Clone, PartialEq, Eq
Source: crates/calternal-notes-core/src/links.rs:85
WikilinkConversion
Section titled “WikilinkConversion”pub struct WikilinkConversionOne wikilink change produced by the bulk Markdown conversion planner.
Fields
pub before: Stringpub after: Stringpub line: usize
Implements: Debug, Clone, PartialEq, Eq
Source: crates/calternal-notes-core/src/links.rs:77
WikilinkConversionPlan
Section titled “WikilinkConversionPlan”pub struct WikilinkConversionPlanA preview result for a bulk Wikilink conversion. content is the exact
candidate text; callers must still compare the source version before write.
Fields
pub content: Stringpub changes: Vec<WikilinkConversion>pub unresolved: Vec<UnresolvedWikilink>
Implements: Debug, Clone, PartialEq, Eq
Source: crates/calternal-notes-core/src/links.rs:94
LinkKind
Section titled “LinkKind”pub enum LinkKindNo doc comment.
Variants
LinkEmbedWikiLinkWikiEmbed
Implements: Debug, Clone, Copy, PartialEq, Eq
LinkKind::is_embed
Section titled “LinkKind::is_embed”pub fn is_embed(self) -> boolNo doc comment.
LinkKind::is_wikilink
Section titled “LinkKind::is_wikilink”pub fn is_wikilink(self) -> boolNo doc comment.
Source: crates/calternal-notes-core/src/links.rs:20
Functions
Section titled “Functions”convert_unique_wikilinks
Section titled “convert_unique_wikilinks”pub fn convert_unique_wikilinks(text: &str, source_path: &str, targets: &[NoteTarget]) -> StringConvert only uniquely resolved wikilinks to ordinary Markdown links. Ambiguous, unresolved, and escaped wikilinks keep their original bytes.
Source: crates/calternal-notes-core/src/links.rs:569
extract_inline_tag_refs
Section titled “extract_inline_tag_refs”pub fn extract_inline_tag_refs(text: &str) -> Vec<TagReference>Extract every tag token with its byte span. Composer parsing uses these spans to remove only the tag bytes and preserve all nearby title words.
Source: crates/calternal-notes-core/src/links.rs:1103
extract_note_features
Section titled “extract_note_features”pub fn extract_note_features(text: &str) -> NoteFeaturesScan links, embeds, inline tags, and trailing block IDs from a Note.
Source: crates/calternal-notes-core/src/links.rs:101
note_link_anchors
Section titled “note_link_anchors”pub fn note_link_anchors(text: &str) -> Vec<String>Heading and block anchors supported by the stored Note text.
Source: crates/calternal-notes-core/src/links.rs:775
note_tags_union
Section titled “note_tags_union”pub fn note_tags_union(text: &str) -> Vec<String>Union inline and frontmatter tags in encounter order, keeping the first
occurrence of each exact tag. Namespaces such as area/work stay intact.
Source: crates/calternal-notes-core/src/links.rs:265
plan_wikilink_conversion
Section titled “plan_wikilink_conversion”pub fn plan_wikilink_conversion( text: &str, source_path: &str, targets: &[NoteTarget], convert_unresolved: bool,) -> WikilinkConversionPlanPlan an explicit bulk conversion. Unlike editor-time conversion, this
writes Home-relative destinations without the editor’s ./ prefix and
reports references that remain unresolved. The optional unsafe mode turns
those remaining references into literal Markdown destinations.
Source: crates/calternal-notes-core/src/links.rs:618
redact_note_references
Section titled “redact_note_references”pub fn redact_note_references(text: &str) -> StringRemove Markdown links and embeds before a Note body is shown outside its Home. A public linked Note may contain references to private files; keeping the complete reference hidden avoids both fetching the file and revealing its name in a label or destination. Code examples stay intact.
Source: crates/calternal-notes-core/src/links.rs:146
redact_shared_note_references
Section titled “redact_shared_note_references”pub fn redact_shared_note_references(text: &str) -> StringShared Note pages keep ordinary external links usable and replace Home References with a neutral label (#1034, DESIGN §54). External embeds stay hidden too: viewing a share must not fetch third-party image bytes.
Source: crates/calternal-notes-core/src/links.rs:153
relative_target
Section titled “relative_target”pub fn relative_target(source_path: &str, target_path: &str) -> StringBuild the relative Markdown destination from the Note at source_path to
the Home path target_path, e.g. Notes/a.md → Documents/x.png gives
../Documents/x.png. Prefix same-folder and child paths with ./ so they
remain relative when every unprefixed multi-part path is Home-rooted.
Source: crates/calternal-notes-core/src/links.rs:1201
resolve_note_relative_target
Section titled “resolve_note_relative_target”pub fn resolve_note_relative_target(source_path: &str, target: &str) -> Option<String>Resolve a CommonMark destination from the source Note’s parent directory. Unlike the legacy Home-root resolver, this treats every unprefixed path as source-relative; imported Markdown depends on this rule (#856, DESIGN §9).
Source: crates/calternal-notes-core/src/links.rs:323
resolve_relative_target
Section titled “resolve_relative_target”pub fn resolve_relative_target(source_path: &str, target: &str) -> Option<String>Resolve a relative Markdown destination against the source Note path.
External URLs and absolute paths return None; fragments and queries stay
attached to a successfully resolved relative path.
Source: crates/calternal-notes-core/src/links.rs:316
rewrite_link_target
Section titled “rewrite_link_target”pub fn rewrite_link_target(text: &str, old: &str, new: &str) -> StringRewrite links that resolve to old from a conventional Note beside the
target. This convenience form covers canonical Notes/... and sibling
relative forms. Use rewrite_link_target_from when the source path is known.
Source: crates/calternal-notes-core/src/links.rs:367
rewrite_link_target_from
Section titled “rewrite_link_target_from”pub fn rewrite_link_target_from(text: &str, source_path: &str, old: &str, new: &str) -> StringRewrite only destinations that resolve to old from source_path.
Source: crates/calternal-notes-core/src/links.rs:372
rewrite_link_targets_for_move
Section titled “rewrite_link_targets_for_move”pub fn rewrite_link_targets_for_move( text: &str, source_path: &str, old_prefix: &str, new_prefix: &str,) -> StringRewrite Markdown destinations below a moved Home path while preserving relative form, anchors, queries, labels and code. Files migrations use this for attachment moves because these targets are paths, not folder semantics (#618; DESIGN §§33 and 40).
Source: crates/calternal-notes-core/src/links.rs:399
rewrite_link_targets_for_moves
Section titled “rewrite_link_targets_for_moves”pub fn rewrite_link_targets_for_moves( text: &str, source_path: &str, moves: &[(String, String)],) -> StringRewrite Markdown destinations for a batch of moved Home paths in one scan. The longest matching source prefix wins so conflict-copy links override the enclosing folder move without rescanning every link (#618; DESIGN §40).
Source: crates/calternal-notes-core/src/links.rs:415
rewrite_links_for_move
Section titled “rewrite_links_for_move”pub fn rewrite_links_for_move(text: &str, old_source: &str, new_source: &str) -> StringRebase relative Markdown destinations when the source Note moves. Explicit Home-root paths and unresolved wikilink sugar retain their original bytes.
Source: crates/calternal-notes-core/src/links.rs:549
rewrite_note_tag_prefix
Section titled “rewrite_note_tag_prefix”pub fn rewrite_note_tag_prefix(text: &str, old: &str, new: &str) -> StringRewrite one tag and its nested tags in Markdown without changing nearby text.
Frontmatter edits splice scalar spans without moving fields. Inline tokens use the scanner’s byte ranges so code, links, escaped hashes, and prose stay byte-for-byte intact.
Source: crates/calternal-notes-core/src/links.rs:274
wikilink_match_keys
Section titled “wikilink_match_keys”pub fn wikilink_match_keys(path: &str, title: &str) -> Vec<String>Keys that can resolve [[reference]] against one Note’s title and path.
The host stores these in an indexed table so writes do not scan every Note.
Source: crates/calternal-notes-core/src/links.rs:746
wikilink_matches_note
Section titled “wikilink_matches_note”pub fn wikilink_matches_note(reference: &str, path: &str, title: &str) -> boolCheck a reference with the same resolver used by editor-time conversion.