Compare commits
3 Commits
ab33730830
...
56348a6d54
Author | SHA1 | Date | |
---|---|---|---|
![]() |
56348a6d54 | ||
![]() |
65e142a215 | ||
![]() |
aa0a0b890e |
@ -1,3 +1,6 @@
|
||||
[[./simple.org]]
|
||||
[[../simple.org]]
|
||||
[[/simple.org]]
|
||||
[[file:simple.org]]
|
||||
[[file:sim ple.org]]
|
||||
|
||||
|
@ -4,3 +4,4 @@
|
||||
|
||||
[[cat::bat]]
|
||||
#+LINK: cat dog%s
|
||||
[[cat:bat]]
|
||||
|
@ -2,6 +2,7 @@ use std::borrow::Cow;
|
||||
|
||||
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_till1;
|
||||
use nom::bytes::complete::take_until;
|
||||
@ -183,8 +184,8 @@ fn apply_link_templates<'b, 'g, 'r, 's>(
|
||||
) -> Option<String> {
|
||||
let (remaining, key) = opt(map(
|
||||
tuple((
|
||||
recognize(take_until::<_, _, nom::error::Error<_>>("::")),
|
||||
tag("::"),
|
||||
recognize(take_until::<_, _, nom::error::Error<_>>(":")),
|
||||
is_a(":"),
|
||||
)),
|
||||
|(key, _)| key,
|
||||
))(input)
|
||||
@ -205,6 +206,7 @@ fn apply_link_templates<'b, 'g, 'r, 's>(
|
||||
let inject_value = Into::<&str>::into(remaining);
|
||||
let mut ret = String::with_capacity(replacement_template.len() + inject_value.len());
|
||||
let mut state = ParserState::Normal;
|
||||
let mut injected_value = false;
|
||||
for c in replacement_template.chars() {
|
||||
state = match (&state, c) {
|
||||
(ParserState::Normal, '%') => ParserState::Percent,
|
||||
@ -214,6 +216,7 @@ fn apply_link_templates<'b, 'g, 'r, 's>(
|
||||
}
|
||||
(ParserState::Percent, 's') => {
|
||||
ret.push_str(inject_value);
|
||||
injected_value = true;
|
||||
ParserState::Normal
|
||||
}
|
||||
(ParserState::Percent, _) => {
|
||||
@ -228,12 +231,15 @@ fn apply_link_templates<'b, 'g, 'r, 's>(
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if !injected_value {
|
||||
ret.push_str(inject_value);
|
||||
}
|
||||
Some(ret)
|
||||
}
|
||||
|
||||
fn file_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s>> {
|
||||
let (remaining, (raw_link, (_, path, search_option))) = consumed(tuple((
|
||||
tag("file:"),
|
||||
alt((tag("file:"), peek(tag(".")), peek(tag("/")))),
|
||||
recognize(many_till(anychar, alt((peek(tag("::")), eof)))),
|
||||
opt(map(tuple((tag("::"), rest)), |(_, search_option)| {
|
||||
search_option
|
||||
|
Loading…
x
Reference in New Issue
Block a user