* [PATCH] alt for inline thumbnail
@ 2011-04-22 8:43 Manuel Giraud
2011-05-02 7:31 ` Carsten Dominik
0 siblings, 1 reply; 2+ messages in thread
From: Manuel Giraud @ 2011-04-22 8:43 UTC (permalink / raw)
To: emacs-orgmode
[-- 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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] alt for inline thumbnail
2011-04-22 8:43 [PATCH] alt for inline thumbnail Manuel Giraud
@ 2011-05-02 7:31 ` Carsten Dominik
0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2011-05-02 7:31 UTC (permalink / raw)
To: Manuel Giraud; +Cc: emacs-orgmode
On Apr 22, 2011, at 10:43 AM, Manuel Giraud wrote:
>
> 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.
>
> <0002-org-html.el-org-html-handle-links-use-fragment-part-.patch>
To me, this looks like the wrong approach. Instead, the ATTR_HTML
should be applied properly also in this case.
- Carsten
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-02 7:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-22 8:43 [PATCH] alt for inline thumbnail Manuel Giraud
2011-05-02 7:31 ` Carsten Dominik
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.