use libimagstore::store::Store;
use libimagstore::store::Entry;
use libimagentrymarkdown::processor::LinkProcessor;
use failure::Fallible as Result;
use failure::ResultExt;
use failure::Error;
pub trait WikiEntry {
fn autolink(&mut self, store: &Store) -> Result<()>;
fn autolink_with_processor(&mut self, store: &Store, processor: LinkProcessor) -> Result<()>;
}
impl WikiEntry for Entry {
fn autolink(&mut self, store: &Store) -> Result<()> {
let processor = LinkProcessor::default()
.process_links(true)
.create_targets(true)
.process_urls(true)
.process_refs(true);
self.autolink_with_processor(store, processor)
}
fn autolink_with_processor(&mut self, store: &Store, processor: LinkProcessor) -> Result<()> {
processor.process(self, store)
.context(format_err!("Auto Link error: {}", self.get_location()))
.map_err(Error::from)
}
}