diff options
author | Sebastian Wiesner <sebastian@swsnr.de> | 2018-10-30 22:10:44 +0100 |
---|---|---|
committer | Sebastian Wiesner <sebastian@swsnr.de> | 2018-10-30 22:10:44 +0100 |
commit | 832baab06875cd6367e30ab79226678a5fe33683 (patch) | |
tree | a77f560a3e078b198a5ba3b11467b1542990b84f /src | |
parent | a35a13070e635eaf23352c54d07c55afbfed44cb (diff) |
Make resource use optional
Fix compiler warnings with --no-default-features by removing unused code.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 31 | ||||
-rw-r--r-- | src/resources.rs | 7 | ||||
-rw-r--r-- | src/terminal/mod.rs | 3 |
3 files changed, 29 insertions, 12 deletions
@@ -34,12 +34,14 @@ #[cfg(feature = "terminology")] extern crate immeta; +#[cfg(feature = "resources")] +extern crate url; + extern crate ansi_term; extern crate failure; extern crate pulldown_cmark; extern crate syntect; extern crate term_size; -extern crate url; use ansi_term::{Colour, Style}; use failure::Error; @@ -53,6 +55,8 @@ use std::path::Path; use syntect::easy::HighlightLines; use syntect::highlighting::{Theme, ThemeSet}; use syntect::parsing::SyntaxSet; + +#[cfg(feature = "resources")] use url::Url; mod resources; @@ -142,14 +146,16 @@ struct Link<'a> { } /// Input context. -struct InputContext<'a> { +#[cfg(feature = "resources")] +struct ResourceContext<'a> { /// The base directory, to resolve relative paths. base_dir: &'a Path, /// What resources we may access when processing markdown. resource_access: ResourceAccess, } -impl<'a> InputContext<'a> { +#[cfg(feature = "resources")] +impl<'a> ResourceContext<'a> { /// Resolve a reference in the input. /// /// If `reference` parses as URL return the parsed URL. Otherwise assume @@ -239,8 +245,9 @@ struct ImageContext { /// Context for TTY rendering. struct Context<'a, W: Write + 'a> { + #[cfg(feature = "resources")] /// Context for input. - input: InputContext<'a>, + resources: ResourceContext<'a>, /// Context for output. output: OutputContext<'a, W>, /// Context for styling @@ -269,8 +276,14 @@ impl<'a, W: Write> Context<'a, W> { syntax_set: SyntaxSet, theme: &'a Theme, ) -> Context<'a, W> { + #[cfg(not(feature = "resources"))] + { + drop(base_dir); + drop(resource_access) + } Context { - input: InputContext { + #[cfg(feature = "resources")] + resources: ResourceContext { base_dir, resource_access, }, @@ -590,7 +603,7 @@ fn start_tag<'a, W: Write>(ctx: &mut Context<W>, tag: Tag<'a>) -> Result<(), Err match ctx.output.capabilities.links { #[cfg(feature = "osc8_links")] LinkCapability::OSC8(ref osc8) => { - if let Some(url) = ctx.input.resolve_reference(&destination) { + if let Some(url) = ctx.resources.resolve_reference(&destination) { osc8.set_link(ctx.output.writer, url.as_str())?; ctx.links.inside_inline_link = true; } @@ -604,9 +617,9 @@ fn start_tag<'a, W: Write>(ctx: &mut Context<W>, tag: Tag<'a>) -> Result<(), Err Image(link, _title) => match ctx.output.capabilities.image { #[cfg(feature = "terminology")] ImageCapability::Terminology(ref mut terminology) => { - let access = ctx.input.resource_access; + let access = ctx.resources.resource_access; if let Some(url) = ctx - .input + .resources .resolve_reference(&link) .filter(|url| access.permits(url)) { @@ -685,7 +698,7 @@ fn end_tag<'a, W: Write>(ctx: &mut Context<'a, W>, tag: Tag<'a>) -> Result<(), E LinkCapability::OSC8(ref osc8) => { osc8.clear_link(ctx.output.writer)?; } - _ => {} + LinkCapability::None => {} } ctx.links.inside_inline_link = false; } else { diff --git a/src/resources.rs b/src/resources.rs index b1323cc..9c6bec6 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -14,6 +14,7 @@ //! Access to resources referenced from markdown documents. +#[cfg(feature = "resources")] use url::Url; /// What kind of resources mdcat may access when rendering. @@ -28,9 +29,10 @@ pub enum ResourceAccess { RemoteAllowed, } +#[cfg(feature = "resources")] impl ResourceAccess { /// Whether the resource access permits access to the given `url`. - pub fn permits(&self, url: &Url) -> bool { + pub fn permits(self, url: &Url) -> bool { match self { ResourceAccess::LocalOnly if is_local(url) => true, ResourceAccess::RemoteAllowed => true, @@ -39,7 +41,8 @@ impl ResourceAccess { } } -pub fn is_local(url: &Url) -> bool { +#[cfg(feature = "resources")] +fn is_local(url: &Url) -> bool { url.scheme() == "file" && url.to_file_path().is_ok() } diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index dabd879..8041f67 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -18,9 +18,10 @@ mod ansi; pub mod highlighting; -mod osc; mod size; +#[cfg(feature = "osc8_links")] +mod osc; #[cfg(feature = "terminology")] mod terminology; |