diff --git a/bin/core/imag-markdown/src/main.rs b/bin/core/imag-markdown/src/main.rs index dbf19cc9..0aa087e4 100644 --- a/bin/core/imag-markdown/src/main.rs +++ b/bin/core/imag-markdown/src/main.rs @@ -61,10 +61,11 @@ fn main() { "Print one or more imag entries after processing them with a markdown parser", ui::build_ui); + let only_links = rt.cli().is_present("links"); let out = rt.stdout(); let mut outlock = out.lock(); - rt.ids::() + let iter = rt.ids::() .map_err_trace_exit_unwrap() .into_iter() .map(Ok) @@ -73,11 +74,24 @@ fn main() { .map(|ofle| ofle.ok_or_else(|| { err_msg("Entry does not exist but is in store. This is a BUG, please report!") })) - .trace_unwrap_exit() - .map(|fle| libimagentrymarkdown::html::to_html(fle.get_content())) - .trace_unwrap_exit() - .for_each(|html| { - writeln!(outlock, "{}", html).map_err(Error::from).map_err_trace_exit_unwrap(); - }) + .trace_unwrap_exit(); + + if only_links { + iter.map(|fle| libimagentrymarkdown::link::extract_links(fle.get_content())) + .for_each(|links| { + links.iter().for_each(|link| { + writeln!(outlock, "{title}: {link}", title = link.title, link = link.link) + .map_err(Error::from) + .map_err_trace_exit_unwrap(); + }) + }) + + } else { + iter.map(|fle| libimagentrymarkdown::html::to_html(fle.get_content())) + .trace_unwrap_exit() + .for_each(|html| { + writeln!(outlock, "{}", html).map_err(Error::from).map_err_trace_exit_unwrap(); + }) + } } diff --git a/bin/core/imag-markdown/src/ui.rs b/bin/core/imag-markdown/src/ui.rs index 04c7acc7..a2f996c4 100644 --- a/bin/core/imag-markdown/src/ui.rs +++ b/bin/core/imag-markdown/src/ui.rs @@ -28,6 +28,14 @@ use libimagerror::trace::MapErrTrace; pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app + .arg(Arg::with_name("links") + .long("links") + .short("l") + .takes_value(false) + .required(false) + .multiple(false) + .help("Print only the links that can be found in the markdown")) + .arg(Arg::with_name("entry") .index(1) .takes_value(true)