diff --git a/flake.nix b/flake.nix index 4fedd79..e3c6254 100644 --- a/flake.nix +++ b/flake.nix @@ -38,6 +38,7 @@ # Common arguments can be set here to avoid repeating them later commonArgs = { inherit src; + cargoVendorDir = null; buildInputs = [ ] ++ lib.optionals pkgs.stdenv.isDarwin [ # Additional darwin specific inputs can be set here diff --git a/src/export/html.rs b/src/export/html.rs index e0b0bd1..af46085 100644 --- a/src/export/html.rs +++ b/src/export/html.rs @@ -60,6 +60,7 @@ pub struct DefaultHtmlHandler; impl HtmlHandler for DefaultHtmlHandler { fn start(&mut self, mut w: W, element: &Element) -> IOResult<()> { + let image_pattern = ["png", "jpeg", "jpg", "gif", "tiff", "tif", "xbm", "xpm", "pbm", "pgm", "ppm", "pnm", "svg", "webp"]; match element { // container elements Element::SpecialBlock(_) => (), @@ -121,12 +122,26 @@ impl HtmlHandler for DefaultHtmlHandler { Element::Code { value } => write!(w, "{}", HtmlEscape(value))?, Element::FnRef(_fn_ref) => (), Element::InlineCall(_) => (), - Element::Link(link) => write!( - w, - "{}", - HtmlEscape(&link.path), - HtmlEscape(link.desc.as_ref().unwrap_or(&link.path)), - )?, + Element::Link(link) => { + let link_extension = &link.path.split(".").last().unwrap(); + // Orgmode considers something an image both if the pattern + // matches /and/ the description is empty. + if image_pattern.contains(link_extension) && link.desc.is_some() { + write!( + w, + "\"{}\"", + HtmlEscape(&link.path), + HtmlEscape(link.desc.as_ref().unwrap_or(&link.path)), + )? + } else { + write!( + w, + "{}", + HtmlEscape(&link.path), + HtmlEscape(link.desc.as_ref().unwrap_or(&link.path)), + )? + } + }, Element::Macros(_macros) => (), Element::RadioTarget => (), Element::Snippet(snippet) => {