diff --git a/src/context/global_settings.rs b/src/context/global_settings.rs index 57ab48bf..32cad286 100644 --- a/src/context/global_settings.rs +++ b/src/context/global_settings.rs @@ -40,8 +40,8 @@ pub struct GlobalSettings<'g, 's> { /// The allowed protocols for links (for example, the "https" in "https://foo.bar/"). /// - /// COrresponds to org-link-parameters elisp variable. - pub org_link_parameters: &'g [&'g str], + /// Corresponds to org-link-parameters elisp variable. + pub link_parameters: &'g [&'g str], } pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8; @@ -60,7 +60,7 @@ impl<'g, 's> GlobalSettings<'g, 's> { odd_levels_only: HeadlineLevelFilter::default(), footnote_section: "Footnotes", coderef_label_format: "(ref:%s)", - org_link_parameters: &ORG_LINK_PARAMETERS, + link_parameters: &ORG_LINK_PARAMETERS, } } } diff --git a/src/parser/plain_link.rs b/src/parser/plain_link.rs index b1a909a2..fe97fbe3 100644 --- a/src/parser/plain_link.rs +++ b/src/parser/plain_link.rs @@ -32,33 +32,6 @@ use crate::parser::util::get_consumed; use crate::parser::util::WORD_CONSTITUENT_CHARACTERS; use crate::types::PlainLink; -// TODO: Make this a user-provided variable corresponding to elisp's org-link-parameters -const ORG_LINK_PARAMETERS: [&'static str; 23] = [ - "id", - "eww", - "rmail", - "mhe", - "irc", - "info", - "gnus", - "docview", - "bibtex", - "bbdb", - "w3m", - "doi", - "file+sys", - "file+emacs", - "shell", - "news", - "mailto", - "https", - "http", - "ftp", - "help", - "file", - "elisp", -]; - #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn plain_link<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, @@ -113,12 +86,11 @@ fn post<'b, 'g, 'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn protocol<'b, 'g, 'r, 's>( - _context: RefContext<'b, 'g, 'r, 's>, + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, OrgSource<'s>> { - // TODO: This should be defined by org-link-parameters - for link_parameter in ORG_LINK_PARAMETERS { - let result = tag_no_case::<_, _, CustomError<_>>(link_parameter)(input); + for link_parameter in context.get_global_settings().link_parameters { + let result = tag_no_case::<_, _, CustomError<_>>(*link_parameter)(input); match result { Ok((remaining, ent)) => { return Ok((remaining, ent)); diff --git a/src/parser/regular_link.rs b/src/parser/regular_link.rs index 3788fa8f..76f9ec35 100644 --- a/src/parser/regular_link.rs +++ b/src/parser/regular_link.rs @@ -2,7 +2,6 @@ use nom::branch::alt; use nom::bytes::complete::escaped; use nom::bytes::complete::tag; 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; @@ -18,6 +17,7 @@ use nom::sequence::tuple; use super::object_parser::regular_link_description_set_object; use super::org_source::OrgSource; +use super::plain_link::protocol; use super::util::exit_matcher_parser; use super::util::get_consumed; use super::util::maybe_consume_object_trailing_whitespace_if_not_exiting; @@ -99,7 +99,7 @@ struct PathReg<'s> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn pathreg<'b, 'g, 'r, 's>( - _context: RefContext<'b, 'g, 'r, 's>, + context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, PathReg<'s>> { let (remaining, path) = map_parser( @@ -111,18 +111,21 @@ fn pathreg<'b, 'g, 'r, 's>( '\\', anychar, ), - parse_path_reg, + parser_with_context!(parse_path_reg)(context), )(input)?; Ok((remaining, path)) } -fn parse_path_reg<'s>(input: OrgSource<'s>) -> Res, PathReg<'s>> { +fn parse_path_reg<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, PathReg<'s>> { alt(( file_path_reg, id_path_reg, custom_id_path_reg, code_ref_path_reg, - protocol_path_reg, + parser_with_context!(protocol_path_reg)(context), fuzzy_path_reg, ))(input) } @@ -189,9 +192,15 @@ fn code_ref_path_reg<'s>(input: OrgSource<'s>) -> Res, PathReg<'s> )) } -fn protocol_path_reg<'s>(input: OrgSource<'s>) -> Res, PathReg<'s>> { - let (remaining, (raw_link, (protocol, _, path))) = - consumed(tuple((take_until(":"), tag(":"), rest)))(input)?; +fn protocol_path_reg<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, + input: OrgSource<'s>, +) -> Res, PathReg<'s>> { + let (remaining, (raw_link, (protocol, _, path))) = consumed(tuple(( + parser_with_context!(protocol)(context), + tag(":"), + rest, + )))(input)?; Ok(( remaining, PathReg {