aboutsummaryrefslogtreecommitdiff
path: root/ennu-html.el
diff options
context:
space:
mode:
authorArun Isaac2020-03-14 19:20:26 +0530
committerArun Isaac2020-03-15 02:33:54 +0530
commitb1b76a30ed130dd5c077237e2c26bac5ce62cd3b (patch)
treece7f9c8a570da6fcb005a0838d2adaef794a2dba /ennu-html.el
parent28b1aa71052c0288381a66c845d90e6416bb2f9a (diff)
downloadennum-b1b76a30ed130dd5c077237e2c26bac5ce62cd3b.tar.gz
ennum-b1b76a30ed130dd5c077237e2c26bac5ce62cd3b.tar.lz
ennum-b1b76a30ed130dd5c077237e2c26bac5ce62cd3b.zip
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.
Diffstat (limited to 'ennu-html.el')
-rw-r--r--ennu-html.el53
1 files 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)
"</article>"))
+(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 "<a href=\"%s\">%s</a>"
+ (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