Skip to content

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

pub struct LinkReference

No 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: LinkKind
  • pub alias: Option<String>

Implements: Debug, Clone, PartialEq, Eq

Source: crates/calternal-notes-core/src/links.rs:38

pub struct NoteFeatures

No 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

pub struct NoteTarget

No doc comment.

Fields

  • pub path: String
  • pub title: String

Implements: Debug, Clone, PartialEq, Eq

Source: crates/calternal-notes-core/src/links.rs:70

pub struct TagReference

No doc comment.

Fields

  • pub value: String
  • pub span: Range<usize>: The complete source token, including one or two leading # bytes.
  • pub literal: bool: ##tag is an explicit literal namespace escape in the composer.

Implements: Debug, Clone, PartialEq, Eq

Source: crates/calternal-notes-core/src/links.rs:61

pub struct UnresolvedWikilink

A wikilink that the resolver cannot safely turn into a Home link.

Fields

  • pub source: String
  • pub line: usize
  • pub ambiguous: bool

Implements: Debug, Clone, PartialEq, Eq

Source: crates/calternal-notes-core/src/links.rs:85

pub struct WikilinkConversion

One wikilink change produced by the bulk Markdown conversion planner.

Fields

  • pub before: String
  • pub after: String
  • pub line: usize

Implements: Debug, Clone, PartialEq, Eq

Source: crates/calternal-notes-core/src/links.rs:77

pub struct WikilinkConversionPlan

A 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: String
  • pub changes: Vec<WikilinkConversion>
  • pub unresolved: Vec<UnresolvedWikilink>

Implements: Debug, Clone, PartialEq, Eq

Source: crates/calternal-notes-core/src/links.rs:94

pub enum LinkKind

No doc comment.

Variants

  • Link
  • Embed
  • WikiLink
  • WikiEmbed

Implements: Debug, Clone, Copy, PartialEq, Eq

pub fn is_embed(self) -> bool

No doc comment.

pub fn is_wikilink(self) -> bool

No doc comment.

Source: crates/calternal-notes-core/src/links.rs:20

pub fn convert_unique_wikilinks(text: &str, source_path: &str, targets: &[NoteTarget]) -> String

Convert 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

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

pub fn extract_note_features(text: &str) -> NoteFeatures

Scan links, embeds, inline tags, and trailing block IDs from a Note.

Source: crates/calternal-notes-core/src/links.rs:101

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

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

pub fn plan_wikilink_conversion(
text: &str,
source_path: &str,
targets: &[NoteTarget],
convert_unresolved: bool,
) -> WikilinkConversionPlan

Plan 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

pub fn redact_note_references(text: &str) -> String

Remove 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

pub fn redact_shared_note_references(text: &str) -> String

Shared 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

pub fn relative_target(source_path: &str, target_path: &str) -> String

Build 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

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

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

pub fn rewrite_link_target(text: &str, old: &str, new: &str) -> String

Rewrite 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

pub fn rewrite_link_target_from(text: &str, source_path: &str, old: &str, new: &str) -> String

Rewrite only destinations that resolve to old from source_path.

Source: crates/calternal-notes-core/src/links.rs:372

pub fn rewrite_link_targets_for_move(
text: &str,
source_path: &str,
old_prefix: &str,
new_prefix: &str,
) -> String

Rewrite 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

pub fn rewrite_link_targets_for_moves(
text: &str,
source_path: &str,
moves: &[(String, String)],
) -> String

Rewrite 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

pub fn rewrite_links_for_move(text: &str, old_source: &str, new_source: &str) -> String

Rebase 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

pub fn rewrite_note_tag_prefix(text: &str, old: &str, new: &str) -> String

Rewrite 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

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

pub fn wikilink_matches_note(reference: &str, path: &str, title: &str) -> bool

Check a reference with the same resolver used by editor-time conversion.

Source: crates/calternal-notes-core/src/links.rs:762