From 53a6b03ad51ed4e05053a220872c2de72f2d254c Mon Sep 17 00:00:00 2001 From: Manuel Giraud 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) ""))))) +(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 "\""") - '(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 "\""") + '(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