summaryrefslogtreecommitdiff
path: root/ennu-html.el
diff options
context:
space:
mode:
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