diff --git a/Cargo.lock b/Cargo.lock index 2d09c10..daa0607 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,9 +139,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "chrono" -version = "0.4.44" +version = "0.4.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" dependencies = [ "iana-time-zone", "num-traits", @@ -531,9 +531,9 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" [[package]] name = "log" -version = "0.4.31" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "113b30b4cd05f7c06868fdb2854f66a7b9fece9a48425351cd532e810d74024f" +checksum = "953f07c43838f8e6f9758cab68bf5bed85465e7587ebe0b823f1bcd81978ad3a" [[package]] name = "matchit" diff --git a/src/graph.rs b/src/graph.rs index 0fd940c..9cc62a5 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -396,7 +396,7 @@ impl Graph { ); } else { if let Some(destination) = anchor.destination() - && !anchor.external() + && !anchor.absolute() { let trimmed_destination = destination .trim_start_matches("/node/") diff --git a/src/syntax/content/parser/context/anchor.rs b/src/syntax/content/parser/context/anchor.rs index 0fbebb6..2aa172c 100644 --- a/src/syntax/content/parser/context/anchor.rs +++ b/src/syntax/content/parser/context/anchor.rs @@ -34,6 +34,9 @@ pub fn parse( log!(VERBOSE, "End: Next lexeme is a pipe"); buffer.text.push_str(&lexeme.text()); candidate.set_text(&buffer.text.clone()); + if buffer.text.starts_with('/') { + candidate.set_absolute(true); + } } else { log!( VERBOSE, @@ -84,6 +87,13 @@ pub fn parse( "State: Found a pipe, but no boundary: destination follows" ); candidate.set_balanced(true); + if lexeme.match_next_first_char('/') { + log!( + VERBOSE, + "State: Destination starts with a dash, marking as absolute" + ); + candidate.set_absolute(true); + } return true; } else if lexeme.match_char(':') { log!(VERBOSE, "State: Found a colon, marking anchor as external"); @@ -205,8 +215,10 @@ mod tests { fn needless_three_pipe_anchor() { assert_eq!( read("|Node|Destination|"), - concat!(r#"
"#) + concat!( + r#""# + ) ); } @@ -225,9 +237,11 @@ mod tests { fn anchor_to_node_s() { assert_eq!( read("The |letter s|s|'s node: |s|!"), - concat!(r#"The The letter s's node: "#, - r#"s!
"#) + r#"s!"# + ) ); } @@ -246,9 +260,11 @@ mod tests { fn leading_plural_anchor() { assert_eq!( read("Interfaces are |element|s of |system|s."), - concat!(r#"Interfaces are Interfaces are elements of systems.
"#) + r#"title="" href="/node/system">systems."# + ) ); } @@ -268,9 +284,11 @@ mod tests { fn explicit_end_of_destination() { assert_eq!( read("interactions are |basic elements|BasicElements| of systems"), - concat!(r#"interactions are interactions are basic elements of "#, - r#"systems
"#) + r#"systems"# + ) ); } @@ -327,6 +345,21 @@ mod tests { ); } + #[test] + fn absolute_anchor() { + let parse_result = + parser::rich_read("see the |raw endpoints|/data|.", &Graph::load()); + println!("Parsed tokens: {:#?}", parse_result.tokens); + assert_eq!( + parse_result.text.unwrap(), + concat!( + r#"see the "#, + r#"raw endpoints.
"#, + ), + ); + } + #[test] fn http_external_anchor() { assert_eq!( diff --git a/src/syntax/content/parser/token/anchor.rs b/src/syntax/content/parser/token/anchor.rs index 1efecf9..556ac42 100644 --- a/src/syntax/content/parser/token/anchor.rs +++ b/src/syntax/content/parser/token/anchor.rs @@ -11,6 +11,7 @@ pub struct Anchor { node: Option| - Detached edges + Detached connections | - {{ detached_count }} + {{ detached_count }} |
These are the destinations to which connections exist, but the target node doesn't.