Skip to main content

join_relative

Function join_relative 

Source
pub fn join_relative(target: &str, from: &str) -> Option<String>
Expand description

target joined onto from’s folder when it starts with ./ or ../, with the dot segments collapsed. None for any other target, and for one that climbs above the vault root.

Public so a caller such as a rename planner can resolve relative links exactly as LinkIndex::resolve_from does.

§Examples

use markdown_link::join_relative;

assert_eq!(join_relative("../x", "a/b/c.md").as_deref(), Some("a/x"));
assert_eq!(join_relative("./y", "a/b.md").as_deref(), Some("a/y"));
assert_eq!(join_relative("plain", "a/b.md"), None); // not relative
assert_eq!(join_relative("../../x", "a/b.md"), None); // above the root