Add support to only list links
This patch adds support in imag-markdown to only list links that are found in the markdown. The list format includes the link title, which I consider convenient in this case, but still easily scriptable. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
632062caed
commit
df62e6f1b3
2 changed files with 29 additions and 7 deletions
|
@ -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::<crate::ui::PathProvider>()
|
||||
let iter = rt.ids::<crate::ui::PathProvider>()
|
||||
.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();
|
||||
|
||||
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();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue