Fix handling capitalization in macro names.
This commit is contained in:
@@ -5,6 +5,7 @@ use super::util::coalesce_whitespace_escaped;
|
||||
use super::util::coalesce_whitespace_if_line_break;
|
||||
use super::util::remove_line_break;
|
||||
use super::util::remove_whitespace_if_line_break;
|
||||
use super::util::to_lowercase;
|
||||
use super::GetStandardProperties;
|
||||
use super::StandardProperties;
|
||||
|
||||
@@ -149,12 +150,18 @@ pub struct AngleLink<'s> {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct OrgMacro<'s> {
|
||||
pub source: &'s str,
|
||||
pub macro_name: &'s str,
|
||||
/// The macro args from the source.
|
||||
|
||||
/// The key from the source.
|
||||
///
|
||||
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_macro_args` for an equivalent value.
|
||||
pub macro_args: Vec<&'s str>,
|
||||
pub macro_value: &'s str,
|
||||
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_key` for an equivalent value.
|
||||
pub key: &'s str,
|
||||
|
||||
/// The args from the source.
|
||||
///
|
||||
/// This does not take into account the post-processing that you would get from the upstream emacs org-mode AST. Use `get_args` for an equivalent value.
|
||||
pub args: Vec<&'s str>,
|
||||
|
||||
pub value: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -739,8 +746,12 @@ impl<'s> AngleLink<'s> {
|
||||
}
|
||||
|
||||
impl<'s> OrgMacro<'s> {
|
||||
pub fn get_macro_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b {
|
||||
self.macro_args
|
||||
pub fn get_key<'b>(&'b self) -> Cow<'s, str> {
|
||||
to_lowercase(self.key)
|
||||
}
|
||||
|
||||
pub fn get_args<'b>(&'b self) -> impl Iterator<Item = Cow<'s, str>> + 'b {
|
||||
self.args
|
||||
.iter()
|
||||
.map(|arg| coalesce_whitespace_escaped('\\', |c| ",".contains(c))(*arg))
|
||||
}
|
||||
|
||||
@@ -451,6 +451,14 @@ enum CoalesceWhitespaceEscaped {
|
||||
},
|
||||
}
|
||||
|
||||
pub(crate) fn to_lowercase<'s>(input: &'s str) -> Cow<'s, str> {
|
||||
if input.chars().any(|c| !c.is_lowercase()) {
|
||||
Cow::Owned(input.to_lowercase())
|
||||
} else {
|
||||
Cow::Borrowed(input)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user