Skip to main content

LinkProcessor

Struct LinkProcessor 

Source
pub struct LinkProcessor { /* private fields */ }
Expand description

A link Processor which collects the links from a Markdown and passes them on to libimagentrylink functionality

The processor can be configured to

  • Process internal links (from store entry to store entry)
  • Process internal links with automatically creating targets If an internal link is encountered, the corrosponding target must be present in the store. If it is not, it will either be created or the processing fails
  • Process external links (from store entry to URL)
  • Process refs (from store entry to files on the filesystem and outside of the store) (default: false)

§Note

There’s no LinkProcessor::new() function, please use LinkProcessor::default().

Implementations§

Source§

impl LinkProcessor

Switch internal link processing on/off

Internal links are links which are simply dirctory/file, but not /directory/file, as beginning an id with / is discouraged in imag.

Source

pub fn create_targets(self, b: bool) -> Self

Switch internal link target creation on/off

If a link points to a non-existing imag entry, a false here will cause the processor to return an error from process(). A true setting will create the entry and then fetch it to link it to the processed entry.

Source

pub fn process_urls(self, b: bool) -> Self

Switch external link processing on/off

An external link must start with https:// or http://.

Source

pub fn process_refs(self, b: bool) -> Self

Switch ref processing on/off

A Ref is to be expected beeing a link with file::/// at the beginning.

Source

pub fn process<'a>(&self, entry: &mut Entry, store: &'a Store) -> Result<()>

Process an Entry for its links

§Notice

Whenever a “ref” is created, that means when a URL points to a filesystem path (normally when using file:///home/user/foobar.file for example), the current implementation uses libimagentryref to create make the entry into a ref.

The configuration of the libimagentryref::reference::Reference::make_ref() call is as follows:

  • Name of the collection: “root”
  • Configuration: {"root": "/"}

This implementation might change in the future, so that the configuration and the name of the collection can be passed to the function, or in a way that the user is asked what to do during the runtime of this function.

§Warning

When LinkProcessor::create_targets() was called to set the setting to true, this function returns all errors returned by the Store.

That means:

  • For an internal link, the linked target is created if create_targets() is true, else error
  • For an external link, if create_targets() is true, libimagentrylink creates the external link entry, else the link is ignored
  • all other cases do not create elements in the store

Trait Implementations§

Source§

impl Default for LinkProcessor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.