From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kodi Arfer Subject: Standalone hyperlinked images in HTML export Date: Sun, 30 Jun 2013 16:07:19 -0400 Message-ID: <51D08FF7.3020002@arfer.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030406000403050406060305" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtNu8-00048u-G9 for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 16:07:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UtNu5-0000el-Li for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 16:07:24 -0400 Received: from mxout-08.mxes.net ([216.86.168.183]:26289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtNu5-0000eZ-F7 for emacs-orgmode@gnu.org; Sun, 30 Jun 2013 16:07:21 -0400 Received: from [192.168.1.103] (unknown [76.117.57.192]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id 3B55050A85 for ; Sun, 30 Jun 2013 16:07:20 -0400 (EDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------030406000403050406060305 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit The manual explains in "Images in HTML export" that you can make an image a hyperlink like this: [[file:highres.jpg][file:thumb.jpg]] where thumb.jpg becomes the 'src' and highres.jpg becomes the 'href'. One might infer it should also be possible to link to something other than an image, like this: [[http://gnu.org][http://example.com/gnu-head.jpg]] For example, try exporting this file: #+begin_src org Some initial text. [[http://example.com/a.png]] Some text between images 1 and 2. [[http://eeyup.com][http://example.com/b.png]] Some text between images 2 and 3. http://example.com/c.png Some trailing text. #+end_src You do indeed get b.png in the output, but the exporter doesn't regard the image as standalone, so it doesn't get put in a
(or, in HTML5 mode,
) like the others, and if you add a #+CAPTION, no caption will be included. The attached patch to master shows how this can be fixed, but I hesitate to recommend applying it because two new bugs are immediately apparent: 1. Figure numbers are screwed up. If you add #+CAPTIONs to each image in the above file, the figure numbers go Figure 1, Figure 3, Figure 4. 2. The ... gets wrapped around the whole
or
, not just the . This breaks markup validity (
isn't allowed in ) and makes the caption, if you have one, into a giant hyperlink. I think I'm going to stop working on this issue for now, but at least what I've done could be helpful for anybody else who wants to go further down the rabbit hole. P.S. I sent a request for a copyright-assignment form earlier today. --------------030406000403050406060305 Content-Type: text/x-patch; name="0001-ox-html-Allow-standalone-images-to-be-hyperlinked.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-ox-html-Allow-standalone-images-to-be-hyperlinked.patch" >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 --------------030406000403050406060305--