From b1b76a30ed130dd5c077237e2c26bac5ce62cd3b Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sat, 14 Mar 2020 19:20:26 +0530 Subject: Handle image links with separate transcoder. * ennu-html.el (ennu-html-link): New function. (ennu-html): Add ennu-html-link transcoder. Remove :html-inline-image-rules option. (ennu-export-image): Delete function. Unregister it from org-link-parameters. --- ennu-html.el | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/ennu-html.el b/ennu-html.el index bf7cb0f..b1cf217 100644 --- a/ennu-html.el +++ b/ennu-html.el @@ -195,11 +195,10 @@ (org-export-define-derived-backend 'ennu-html 'html :translate-alist - '((inner-template . ennu-html-inner-template)) + '((inner-template . ennu-html-inner-template) + (link . ennu-html-link)) :options-alist - '((:html-inline-image-rules - nil nil '(("image" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")) t) - (:summary "SUMMARY" nil nil parse) + '((:summary "SUMMARY" nil nil parse) (:thumbnail "THUMBNAIL" nil nil t) (:translation-group "TRANSLATION_GROUP" nil nil t))) @@ -265,6 +264,37 @@ (org-html-footnote-section info) "")) +(defun ennu-html-link (link desc info) + ;; We override the html link transcoder to handle image links + ;; differently. We cannot use the `:export' property of + ;; `org-link-parameters' since those functions cannot access the + ;; `info' communication channel. + (let ((path (org-element-property :path link))) + (pcase (org-element-property :type link) + ("image" + ;; Convert image links to file links, get them transcoded by + ;; `org-html-link' and then remove the file:// scheme from the + ;; URI. Finally insert the transcoded image link in a link to a + ;; larger image as specified by the :image-link-width setting. + (format "%s" + (expand-file-name* + (ennu-image-output-filename + path (ennu-setting :image-link-width)) + (ennu-setting :images-directory)) + (replace-regexp-in-string + "src=\"file://" "src=\"" + (org-html-link + (org-element-put-property + (org-element-put-property + link :path (expand-file-name* + (ennu-image-output-filename + path (ennu-setting :default-image-width)) + (ennu-setting :images-directory))) + :type "file") + desc info)))) + ;; Pass other link types to org-html-link + (_ (org-html-link link desc info))))) + ;; TODO: Pass title through org-export-data-with-backend or something ;; similar in order to export org syntax in title (defun ennu-export-post (path desc backend) @@ -277,21 +307,6 @@ (org-link-set-parameters "post" :export 'ennu-export-post) -(defun ennu-export-image (path desc backend) - (let ((img `(img :src ,(expand-file-name* - (ennu-image-output-filename - path (ennu-setting :default-image-width)) - (ennu-setting :images-directory))))) - (xmlgen (if (ennu-setting :image-link-width) - `(a :href ,(expand-file-name* - (ennu-image-output-filename - path (ennu-setting :image-link-width)) - (ennu-setting :images-directory)) - ,img) - img)))) - -(org-link-set-parameters - "image" :export 'ennu-export-image) (defun ennu-export-thumbnail (path desc backend) (xmlgen -- cgit v1.2.3