dotfiles

My personal dotfiles

commit 9efe567511cb5e765b20d8f97d6ed615c530e924
parent 1ed463bc2e0ff8324e01e0b4be0526175583c0fd
Author: Pablo Emilio Escobar Gaviria <pablo-escobar@riseup.net>
Date:   Sat, 26 Dec 2020 01:45:39 +1000

Configure Vim to highlight file as Asciidoc from inside NeoMutt

Also fixed issues with images in Asciidoctor templates used in NeoMutt

Diffstat:
M.config/mutt/asciidoc-template/block_image.html.haml | 4++--
M.config/mutt/asciidoc-template/helpers.rb | 28++++++++++++++++++++++++++++
M.config/mutt/muttrc | 3---
M.config/nvim/init.vim | 2++
4 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/.config/mutt/asciidoc-template/block_image.html.haml b/.config/mutt/asciidoc-template/block_image.html.haml
@@ -1,9 +1,9 @@
 - if attr? :link
   %a{:href => (attr :link)}
     %figure
-      %img{:src => image_uri(attr :target), :alt => (attr :alt), 
+      %img{:src => uri_from_image(attr :target), :alt => (attr :alt), 
         :width => (attr :width), :height => (attr :height)}
 - else
   %figure
-    %img{:src => image_uri(attr :target), :alt => (attr :alt), 
+    %img{:src => uri_from_image(attr :target), :alt => (attr :alt), 
       :width => (attr :width), :height => (attr :height)}
diff --git a/.config/mutt/asciidoc-template/helpers.rb b/.config/mutt/asciidoc-template/helpers.rb
@@ -1,3 +1,5 @@
+require "base64"
+
 # Add custom functions to this module that you want to use in your Haml
 # templates. Within the template you can invoke them as top-level functions
 # just like the built-in helper functions that Haml provides.
@@ -93,4 +95,30 @@ module Haml::Helpers
 
     str.prepend('?') unless str.empty?
   end
+
+  # Encode images as a URI
+  def uri_from_image(path)
+    # If the path is a URL use it
+    if path.start_with? "http"
+      path
+    else
+      format = path.split(".").last
+      path = path.gsub(/^~/, ENV["HOME"]) if ENV["HOME"]
+
+      case format
+      when "ico"
+        format = "vnd.microsoft.icon"
+      when "jpg"
+        format = "jpeg"
+      when "svg"
+        format = "svg+xml"
+      when "tif"
+        format = "tiff"
+      end
+
+      File::open(path, "r") { |file|
+        "data:image/#{format};base64,#{Base64.encode64(file.read)}"
+      }
+    end
+  end
 end
diff --git a/.config/mutt/muttrc b/.config/mutt/muttrc
@@ -47,9 +47,6 @@ color sidebar_divider white default
 
 # ============================== Composing ====================================
 
-# Pass the appropriate flags to nvim
-set editor="nvim -c 'set ft=asciidoc'"
-
 set date_format="%a, %b %d, %Y"
 
 # Format the message with Asciidoctor
diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim
@@ -99,3 +99,5 @@ au BufNewFile,BufRead *.m,*.mathematica set ft=mma
 
 " Supress word wrapping when reading Python source files
 au BufNewFile,BufRead *.py              set textwidth=0
+
+au BufNewFile,BufRead /tmp/neomutt*     set ft=asciidoc