>From fe74b3507795f2664291250250bc24b943f8f12b Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sun, 30 Jun 2013 15:40:33 -0400 Subject: [PATCH] ox-html: Allow standalone images to be hyperlinked * lisp/ox-html.el (org-html-standalone-image-p): If the link is the description of another link, look one more element up the tree to find `paragraph'. * lisp/ox.el (org-export-inline-image-p): When the description is a link, test the description instead of the path. TINYCHANGE --- lisp/ox-html.el | 9 ++++++--- lisp/ox.el | 38 ++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 4753e66..4091bcc 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2579,9 +2579,12 @@ standalone images, do the following. \(org-element-property :caption paragraph\)\)\)" (let ((paragraph (case (org-element-type element) (paragraph element) - (link (and (org-export-inline-image-p - element org-html-inline-image-rules) - (org-export-get-parent element))) + (link (let ((x (and (org-export-inline-image-p + element org-html-inline-image-rules) + (org-export-get-parent element)))) + (if (eq (org-element-type x) 'link) + (org-export-get-parent x) + x))) (t nil)))) (when (eq (org-element-type paragraph) 'paragraph) (when (or (not (and (boundp 'org-html-standalone-image-predicate) diff --git a/lisp/ox.el b/lisp/ox.el index 08fbddd..9179576 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3919,20 +3919,30 @@ type is TYPE. The function will return a non-nil value if any of the provided rules is non-nil. The default rule is `org-export-default-inline-image-rule'. -This only applies to links without a description." - (and (not (org-element-contents link)) - (let ((case-fold-search t) - (rules (or rules org-export-default-inline-image-rule))) - (catch 'exit - (mapc - (lambda (rule) - (and (string= (org-element-property :type link) (car rule)) - (string-match (cdr rule) - (org-element-property :path link)) - (throw 'exit t))) - rules) - ;; Return nil if no rule matched. - nil)))) +This only applies to links without a description, unless the +description is itself a link, as for hyperlinked images in HTML. +In this case, the test is applied to the description instead of +the path." + (let* ((cs (org-element-contents link)) + (dlink (and (= (length cs) 1) + (eq (org-element-type (car cs)) 'link) + (car cs)))) + (when (or dlink (not (org-element-contents link))) + (message "dlink: %s" (show-org-element dlink)) + (when dlink + (setq link dlink)) + (let ((case-fold-search t) + (rules (or rules org-export-default-inline-image-rule))) + (catch 'exit + (mapc + (lambda (rule) + (and (string= (org-element-property :type link) (car rule)) + (string-match (cdr rule) + (org-element-property :path link)) + (throw 'exit t))) + rules) + ;; Return nil if no rule matched. + nil))))) (defun org-export-resolve-coderef (ref info) "Resolve a code reference REF. -- 1.8.1.2