From 120a06055f55aee7eb89c4b1bdcd8b6b063fcc39 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 8 Oct 2023 09:54:10 -0400 Subject: [PATCH] Handle 3 or more slashes in the path for regular links. --- .../object/regular_link/multiple_slashes.org | 20 +++++++++++++++++++ src/parser/regular_link.rs | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 org_mode_samples/object/regular_link/multiple_slashes.org diff --git a/org_mode_samples/object/regular_link/multiple_slashes.org b/org_mode_samples/object/regular_link/multiple_slashes.org new file mode 100644 index 0000000..bb29c8c --- /dev/null +++ b/org_mode_samples/object/regular_link/multiple_slashes.org @@ -0,0 +1,20 @@ +[[file:foo]] +[[file:/bar]] +[[file://baz]] +[[file:///lorem]] +[[file:////ipsum]] +[[file://///dolar]] + +[[foo]] +[[/bar]] +[[//baz]] +[[///lorem]] +[[////ipsum]] +[[/////dolar]] + +[[https:foo]] +[[https:/bar]] +[[https://baz]] +[[https:///lorem]] +[[https:////ipsum]] +[[https://///dolar]] diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index caeefd8..0946ca2 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -4,11 +4,13 @@ use nom::branch::alt; use nom::bytes::complete::escaped; use nom::bytes::complete::is_a; use nom::bytes::complete::tag; +use nom::bytes::complete::take; use nom::bytes::complete::take_till1; use nom::bytes::complete::take_until; use nom::character::complete::anychar; use nom::combinator::consumed; use nom::combinator::eof; +use nom::combinator::flat_map; use nom::combinator::map; use nom::combinator::map_parser; use nom::combinator::opt; @@ -16,6 +18,7 @@ use nom::combinator::peek; use nom::combinator::recognize; use nom::combinator::rest; use nom::combinator::verify; +use nom::multi::many1_count; use nom::multi::many_till; use nom::sequence::tuple; use nom::InputTake; @@ -261,7 +264,7 @@ fn file_path_reg<'b, 'g, 'r, 's>( }); let parser_context = context.with_additional_node(&parser_context); - let (remaining, (raw_link, (application, path, search_option))) = consumed(tuple(( + let (remaining, (raw_link, (application, _, path, search_option))) = consumed(tuple(( alt(( map( tuple(( @@ -277,6 +280,10 @@ fn file_path_reg<'b, 'g, 'r, 's>( map(peek(tag(".")), |_| None), map(peek(tag("/")), |_| None), )), + opt(flat_map( + peek(map(verify(many1_count(tag("/")), |c| *c >= 3), |c| c - 1)), + take, + )), parser_with_context!(text_until_exit)(&parser_context), opt(map( tuple((