Apply the link templates.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::GetStandardProperties;
|
||||
use super::StandardProperties;
|
||||
|
||||
@@ -78,9 +81,9 @@ pub struct PlainText<'s> {
|
||||
pub struct RegularLink<'s> {
|
||||
pub source: &'s str,
|
||||
pub link_type: LinkType<'s>,
|
||||
pub path: &'s str,
|
||||
pub raw_link: &'s str,
|
||||
pub search_option: Option<&'s str>,
|
||||
pub path: Cow<'s, str>,
|
||||
pub raw_link: Cow<'s, str>,
|
||||
pub search_option: Option<Cow<'s, str>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -643,7 +646,7 @@ impl<'s> Timestamp<'s> {
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum LinkType<'s> {
|
||||
File,
|
||||
Protocol(&'s str),
|
||||
Protocol(Cow<'s, str>),
|
||||
Id,
|
||||
CustomId,
|
||||
CodeRef,
|
||||
@@ -659,7 +662,8 @@ enum ParserState {
|
||||
/// Org-mode treats multiple consecutive whitespace characters as a single space. This function performs that transformation.
|
||||
///
|
||||
/// Example: `orgify_text("foo \t\n bar") == "foo bar"`
|
||||
pub(crate) fn orgify_text<'s>(raw_text: &'s str) -> String {
|
||||
pub(crate) fn orgify_text<T: AsRef<str>>(raw_text: T) -> String {
|
||||
let raw_text = raw_text.as_ref();
|
||||
let mut ret = String::with_capacity(raw_text.len());
|
||||
let mut state = ParserState::Normal;
|
||||
for c in raw_text.chars() {
|
||||
@@ -686,28 +690,28 @@ impl<'s> RegularLink<'s> {
|
||||
/// Orgify the raw_link if it contains line breaks.
|
||||
pub fn get_raw_link(&self) -> String {
|
||||
if self.raw_link.contains('\n') {
|
||||
orgify_text(self.raw_link)
|
||||
orgify_text(Borrow::<str>::borrow(&self.raw_link))
|
||||
} else {
|
||||
self.raw_link.to_owned()
|
||||
self.raw_link.clone().into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
/// Orgify the path if it contains line breaks.
|
||||
pub fn get_path(&self) -> String {
|
||||
if self.path.contains('\n') {
|
||||
orgify_text(self.path)
|
||||
orgify_text(Borrow::<str>::borrow(&self.path))
|
||||
} else {
|
||||
self.path.to_owned()
|
||||
self.path.clone().into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
/// Orgify the search_option if it contains line breaks.
|
||||
pub fn get_search_option(&self) -> Option<String> {
|
||||
self.search_option.map(|search_option| {
|
||||
self.search_option.as_ref().map(|search_option| {
|
||||
if search_option.contains('\n') {
|
||||
orgify_text(search_option)
|
||||
} else {
|
||||
search_option.to_owned()
|
||||
search_option.clone().into_owned()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user