From: Kodi Arfer <kodi@arfer.net>
To: emacs-orgmode@gnu.org
Subject: Standalone hyperlinked images in HTML export
Date: Sun, 30 Jun 2013 16:07:19 -0400 [thread overview]
Message-ID: <51D08FF7.3020002@arfer.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1709 bytes --]
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 <img> 'src' and highres.jpg becomes the <a>
'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
<a href="http://eeyup.com"><img src="http://example.com/b.png"
alt="b.png" /></a>
in the output, but the exporter doesn't regard the image as standalone,
so it doesn't get put in a <div> (or, in HTML5 mode, <figure>) 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 <a ...> ... </a> gets wrapped around the whole <div> or <figure>,
not just the <img>. This breaks markup validity (<div> isn't allowed in
<a>) 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.
[-- Attachment #2: 0001-ox-html-Allow-standalone-images-to-be-hyperlinked.patch --]
[-- Type: text/x-patch, Size: 3340 bytes --]
From fe74b3507795f2664291250250bc24b943f8f12b Mon Sep 17 00:00:00 2001
From: Kodi Arfer <git@arfer.net>
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
next reply other threads:[~2013-06-30 20:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-30 20:07 Kodi Arfer [this message]
2013-06-30 22:08 ` Standalone hyperlinked images in HTML export Bastien
2013-07-01 11:50 ` Nicolas Goaziou
2013-07-01 21:01 ` Nicolas Goaziou
2013-07-01 21:26 ` Kodi Arfer
2013-07-02 19:13 ` Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51D08FF7.3020002@arfer.net \
--to=kodi@arfer.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.