From: Manuel Giraud <manuel.giraud@univ-nantes.fr>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] alt for inline thumbnail
Date: Fri, 22 Apr 2011 10:43:35 +0200 [thread overview]
Message-ID: <87zknillqg.fsf@univ-nantes.fr> (raw)
[-- Attachment #1: Type: text/plain, Size: 205 bytes --]
Hi,
Here's a patch to add the following syntax for image link in html
exports:
[[file:hires.jpg][file:thumb.jpg::my description]]
"my description" will be used for the alt attribute of the thumbnail.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org-html.el-org-html-handle-links-use-fragment-part-.patch --]
[-- Type: text/x-patch, Size: 4889 bytes --]
From 53a6b03ad51ed4e05053a220872c2de72f2d254c Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel.giraud@univ-nantes.fr>
Date: Wed, 20 Apr 2011 16:04:17 +0200
Subject: [PATCH 2/2] * org-html.el (org-html-handle-links): use fragment part of an image
description as the alt
---
doc/org.texi | 4 ++-
lisp/org-html.el | 92 +++++++++++++++++++++++++++---------------------------
2 files changed, 49 insertions(+), 47 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index 8ca4426..3ff862e 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -9771,9 +9771,11 @@ image will activate the link. For example, to include a thumbnail that
will link to a high resolution version of the image, you could use:
@example
-[[file:highres.jpg][file:thumb.jpg]]
+[[file:highres.jpg][file:thumb.jpg::my cat hunting a mosquito]]
@end example
+The part after the double colon is used to make the @code{alt} attribute.
+
If you need to add attributes to an inlined image, use a @code{#+ATTR_HTML}.
In the example below we specify the @code{alt} and @code{title} attributes to
support text viewers and accessibility, and align it to the right.
diff --git a/lisp/org-html.el b/lisp/org-html.el
index 7a4564d..4a53f77 100644
--- a/lisp/org-html.el
+++ b/lisp/org-html.el
@@ -854,6 +854,14 @@ MAY-INLINE-P allows inlining it as an image."
(org-export-html-format-desc desc)
"</a>")))))
+(defun org-html-split-path-fragment (fullpath)
+ "Return a cons with car as the path and cdr as the fragment."
+ (save-match-data
+ (if (string-match "::\\(.*\\)" fullpath)
+ (cons (replace-match "" t nil fullpath)
+ (match-string 1 fullpath))
+ (cons fullpath nil))))
+
(defun org-html-handle-links (line opt-plist)
"Return LINE with markup of Org mode links.
OPT-PLIST is the export options list."
@@ -882,15 +890,17 @@ OPT-PLIST is the export options list."
descp (and desc1 (not (equal desc1 desc2)))
desc (or desc1 desc2))
;; Make an image out of the description if that is so wanted
- (when (and descp (org-file-image-p
- desc org-export-html-inline-image-extensions))
- (save-match-data
- (if (string-match "^file:" desc)
- (setq desc (substring desc (match-end 0)))))
- (setq desc (org-add-props
- (concat "<img src=\"" desc "\" alt=\""
- (file-name-nondirectory desc) "\"/>")
- '(org-protected t))))
+ (let* ((components (org-html-split-path-fragment desc))
+ (src (car components))
+ (alt (cdr components)))
+ (when (and descp
+ (org-file-image-p src org-export-html-inline-image-extensions))
+ (save-match-data
+ (if (string-match "^file:" src)
+ (setq src (substring src (match-end 0)))))
+ (setq desc (org-add-props
+ (concat "<img src=\"" src "\" alt=\"" alt "\"/>")
+ '(org-protected t)))))
(cond
((equal type "internal")
(let
@@ -965,44 +975,34 @@ OPT-PLIST is the export options list."
((string= type "file")
;; FILE link
(save-match-data
- (let*
- ((components
- (if
- (string-match "::\\(.*\\)" path)
- (list
- (replace-match "" t nil path)
- (match-string 1 path))
- (list path nil)))
-
- ;;The proper path, without a fragment
- (path-1
- (first components))
-
- ;;The raw fragment
- (fragment-0
- (second components))
-
- ;;Check the fragment. If it can't be used as
- ;;target fragment we'll pass nil instead.
- (fragment-1
- (if
- (and fragment-0
- (not (string-match "^[0-9]*$" fragment-0))
- (not (string-match "^\\*" fragment-0))
- (not (string-match "^/.*/$" fragment-0)))
- (org-solidify-link-text
- (org-link-unescape fragment-0))
- nil))
- (desc-2
- ;;Description minus "file:" and ".org"
- (if (string-match "^file:" desc)
- (let
- ((desc-1 (replace-match "" t t desc)))
- (if (string-match "\\.org$" desc-1)
- (replace-match "" t t desc-1)
- desc-1))
- desc)))
+ (let* ((components (org-html-split-path-fragment path))
+ ;;The proper path, without a fragment
+ (path-1 (car components))
+
+ ;;The raw fragment
+ (fragment-0 (cdr components))
+
+ ;;Check the fragment. If it can't be used as
+ ;;target fragment we'll pass nil instead.
+ (fragment-1
+ (if
+ (and fragment-0
+ (not (string-match "^[0-9]*$" fragment-0))
+ (not (string-match "^\\*" fragment-0))
+ (not (string-match "^/.*/$" fragment-0)))
+ (org-solidify-link-text
+ (org-link-unescape fragment-0))
+ nil))
+ (desc-2
+ ;;Description minus "file:" and ".org"
+ (if (string-match "^file:" desc)
+ (let
+ ((desc-1 (replace-match "" t t desc)))
+ (if (string-match "\\.org$" desc-1)
+ (replace-match "" t t desc-1)
+ desc-1))
+ desc)))
(setq rpl
(if
(and
--
1.7.3.5
[-- Attachment #3: Type: text/plain, Size: 19 bytes --]
--
Manuel Giraud
next reply other threads:[~2011-04-22 8:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-22 8:43 Manuel Giraud [this message]
2011-05-02 7:31 ` [PATCH] alt for inline thumbnail Carsten Dominik
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=87zknillqg.fsf@univ-nantes.fr \
--to=manuel.giraud@univ-nantes.fr \
--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.