Browse Source

Export: Better detection of images that can be inlined.

Two new variables, `org-export-html-inline-image-extensions' and
`org-export-latex-inline-image-extensions' now define the file
extensions that will be considered for inlining images.  The default
for HTML is png, jpg, jpeg, and gif files.  The default for LaTeX is
png, jpg, jpeg, and pdf, assuming processing with `pdflatex'.

For LaTeX export, this can lead to conflicts for links that point
to non-image PDF files.  To avoid that such a link will be inlined by
accident, always give a description text for such a link, one that is
not equal to the path.
Carsten Dominik 17 years ago
parent
commit
03d324ac2b
7 changed files with 73 additions and 15 deletions
  1. 22 0
      ORGWEBPAGE/Changes.org
  2. 4 0
      doc/org.texi
  3. 9 0
      lisp/ChangeLog
  4. 13 3
      lisp/org-exp.el
  5. 14 3
      lisp/org-export-latex.el
  6. 2 2
      lisp/org-mouse.el
  7. 9 7
      lisp/org.el

+ 22 - 0
ORGWEBPAGE/Changes.org

@@ -27,6 +27,22 @@
 
 
 ** Details
 ** Details
 
 
+*** Better handling of inlined images in different backends
+
+    Two new variables govern which kind of files can be inlined
+    during export.  These are
+    =org-export-html-inline-image-extensions= and
+    =org-export-latex-inline-image-extensions=.  Remember that
+    links are turned into an inline image if they are a pure link
+    with no description.  HTML files can inline /.png/, /.jpg/,
+    and /.gif/ files, while LaTeX files, when processed with
+    /pdflatex/, can inline /.png/, /.jpg/, and /.pdf/ files.
+    These also represent the default settings for the new
+    variables.  Note that this means that pure links to /.pdf/
+    files will be inlined - to avoid this for a particular link,
+    make sure that the link has a description part which is not
+    equal to the link part.
+
 *** The relative timer can be paused
 *** The relative timer can be paused
 
 
     The new command `C-c C-x ,' will pause the relative timer.
     The new command `C-c C-x ,' will pause the relative timer.
@@ -43,12 +59,18 @@
 
 
 : #+INCLUDE "~/.emacs" src emacs-lisp -n -r
 : #+INCLUDE "~/.emacs" src emacs-lisp -n -r
 
 
+    Thanks to Manish for pointing out that this was not yet
+    supported.
+
 *** Links by ID now continue to work in HTML exported files
 *** Links by ID now continue to work in HTML exported files
 
 
     If you make links by ID, these links will now still work in
     If you make links by ID, these links will now still work in
     HTML exported files, provided that you keep the relative path
     HTML exported files, provided that you keep the relative path
     from link to target file the same.
     from link to target file the same.
 
 
+    Thanks to Friedrich Delgado Friedrichs for pushing this over
+    the line.
+
 * Version 6.17
 * Version 6.17
 
 
 ** Overview
 ** Overview

+ 4 - 0
doc/org.texi

@@ -8190,6 +8190,10 @@ options that can be used in the optional argument of the
 [[./img/sed-hr4049.pdf]]
 [[./img/sed-hr4049.pdf]]
 @end example
 @end example
 
 
+The default settings will recognize files types that can be included as
+images during processing by pdflatex (@file{png}, @file{jpg}, and @file{pdf}
+files).  If you process your files in a different way, you may need to
+customize the variable @code{org-export-latex-inline-image-extensions}.
 
 
 @node XOXO export, iCalendar export, LaTeX and PDF export, Exporting
 @node XOXO export, iCalendar export, LaTeX and PDF export, Exporting
 @section XOXO export
 @section XOXO export

+ 9 - 0
lisp/ChangeLog

@@ -1,5 +1,14 @@
 2009-01-18  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-01-18  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
+	* org-exp.el (org-export-as-html): Only check for images files
+	that really can be inlined
+
+	* org.el (org-image-file-name-regexp, org-file-image-p): Allow the
+	list of extensions to be a parameter.
+
+	* org-exp.el (org-export-html-inline-image-extensions): New
+	variable.
+
 	* org-agenda.el (org-prepare-agenda): Use
 	* org-agenda.el (org-prepare-agenda): Use
 	`org-agenda-block-separator'.
 	`org-agenda-block-separator'.
 	(org-agenda-block-separator): New option.
 	(org-agenda-block-separator): New option.

+ 13 - 3
lisp/org-exp.el

@@ -693,6 +693,12 @@ be linked only."
 		 (const :tag "Always" t)
 		 (const :tag "Always" t)
 		 (const :tag "When there is no description" maybe)))
 		 (const :tag "When there is no description" maybe)))
 
 
+(defcustom org-export-html-inline-image-extensions
+  '("png" "jpeg" "jpg" "gif")
+  "Extensions of image files that can be inlined into HTML."
+  :group 'org-export-html
+  :type '(repeat (string :tag "Extension")))
+
 ;; FIXME: rename
 ;; FIXME: rename
 (defcustom org-export-html-expand t
 (defcustom org-export-html-expand t
   "Non-nil means, for HTML export, treat @<...> as HTML tag.
   "Non-nil means, for HTML export, treat @<...> as HTML tag.
@@ -3562,7 +3568,8 @@ lang=\"%s\" xml:lang=\"%s\">
 		  descp (and desc1 (not (equal desc1 desc2)))
 		  descp (and desc1 (not (equal desc1 desc2)))
 		  desc (or desc1 desc2))
 		  desc (or desc1 desc2))
 	    ;; Make an image out of the description if that is so wanted
 	    ;; Make an image out of the description if that is so wanted
-	    (when (and descp (org-file-image-p desc))
+	    (when (and descp (org-file-image-p
+			      desc org-export-html-inline-image-extensions))
 	      (save-match-data
 	      (save-match-data
 		(if (string-match "^file:" desc)
 		(if (string-match "^file:" desc)
 		    (setq desc (substring desc (match-end 0)))))
 		    (setq desc (substring desc (match-end 0)))))
@@ -3596,7 +3603,8 @@ lang=\"%s\" xml:lang=\"%s\">
 	      ;; standard URL, just check if we need to inline an image
 	      ;; standard URL, just check if we need to inline an image
 	      (if (and (or (eq t org-export-html-inline-images)
 	      (if (and (or (eq t org-export-html-inline-images)
 			   (and org-export-html-inline-images (not descp)))
 			   (and org-export-html-inline-images (not descp)))
-		       (org-file-image-p path))
+		       (org-file-image-p
+			path org-export-html-inline-image-extensions))
 		  (setq rpl (org-export-html-format-image
 		  (setq rpl (org-export-html-format-image
 			     (concat type ":" path)))
 			     (concat type ":" path)))
 		(setq link (concat type ":" path))
 		(setq link (concat type ":" path))
@@ -3640,7 +3648,9 @@ lang=\"%s\" xml:lang=\"%s\">
 			(if (functionp link-validate)
 			(if (functionp link-validate)
 			    (funcall link-validate filename current-dir)
 			    (funcall link-validate filename current-dir)
 			  t))
 			  t))
-		  (setq file-is-image-p (org-file-image-p filename))
+		  (setq file-is-image-p
+			(org-file-image-p
+			 filename org-export-html-inline-image-extensions))
 		  (setq thefile (if abs-p (expand-file-name filename) filename))
 		  (setq thefile (if abs-p (expand-file-name filename) filename))
 		  (when (and org-export-html-link-org-files-as-html
 		  (when (and org-export-html-link-org-files-as-html
 			     (string-match "\\.org$" thefile))
 			     (string-match "\\.org$" thefile))

+ 14 - 3
lisp/org-export-latex.el

@@ -247,6 +247,16 @@ and `org-export-with-tags' instead."
   :group 'org-export-latex
   :group 'org-export-latex
   :type 'string)
   :type 'string)
 
 
+(defcustom org-export-latex-inline-image-extensions
+  '("pdf" "jpeg" "jpg" "png")
+  "Extensions of image files that can be inlined into LaTeX.
+Note that this depends on the way the LaTeX file is processed.
+The default setting (pdf and jpg) assumes that pdflatex is doing the
+processing.  If you are using latex and dvips or something similar,
+only postscript files can be included."
+  :group 'org-export-html
+  :type '(repeat (string :tag "Extension")))
+
 (defcustom org-export-latex-coding-system nil
 (defcustom org-export-latex-coding-system nil
   "Coding system for the exported LaTex file."
   "Coding system for the exported LaTex file."
   :group 'org-export-latex
   :group 'org-export-latex
@@ -1207,9 +1217,10 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 		   ((equal type "mailto")
 		   ((equal type "mailto")
 		    (concat type ":" raw-path))
 		    (concat type ":" raw-path))
 		   ((equal type "file")
 		   ((equal type "file")
-		    (if (and (or (org-file-image-p (expand-file-name raw-path))
-				 (string-match "\\.\\(pdf\\|jpg\\|ps\\|eps\\)$"
-					       raw-path))
+		    (if (and (org-file-image-p
+			      (expand-file-name
+			       raw-path)
+			      org-export-latex-inline-image-extensions)
 			     (equal desc full-raw-path))
 			     (equal desc full-raw-path))
 			(setq imgp t)
 			(setq imgp t)
 		      (progn (when (string-match "\\(.+\\)::.+" raw-path)
 		      (progn (when (string-match "\\(.+\\)::.+" raw-path)

+ 2 - 2
lisp/org-mouse.el

@@ -219,8 +219,8 @@ this function is called.  Otherwise, the current major mode menu is used."
 	    (funcall org-mouse-context-menu-function event)
 	    (funcall org-mouse-context-menu-function event)
 	  (if (fboundp 'mouse-menu-major-mode-map)
 	  (if (fboundp 'mouse-menu-major-mode-map)
 	      (popup-menu (mouse-menu-major-mode-map) event prefix)
 	      (popup-menu (mouse-menu-major-mode-map) event prefix)
-	    (with-no-warnings ; don't warn about fallback, obsolete since 23.1
-	      (mouse-major-mode-menu event prefix)))))
+	    (org-no-warnings ; don't warn about fallback, obsolete since 23.1
+	     (mouse-major-mode-menu event prefix)))))
     (setq this-command 'mouse-save-then-kill)
     (setq this-command 'mouse-save-then-kill)
     (mouse-save-then-kill event)))
     (mouse-save-then-kill event)))
 
 

+ 9 - 7
lisp/org.el

@@ -14165,13 +14165,15 @@ not an indirect buffer."
 	(or (buffer-base-buffer buf) buf)
 	(or (buffer-base-buffer buf) buf)
       nil)))
       nil)))
 
 
-(defun org-image-file-name-regexp ()
-  "Return regexp matching the file names of images."
-  (if (fboundp 'image-file-name-regexp)
+(defun org-image-file-name-regexp (&optional extensions)
+  "Return regexp matching the file names of images.
+If EXTENSIONS is given, only match these."
+  (if (and (not extensions) (fboundp 'image-file-name-regexp))
       (image-file-name-regexp)
       (image-file-name-regexp)
     (let ((image-file-name-extensions
     (let ((image-file-name-extensions
-	   '("png" "jpeg" "jpg" "gif" "tiff" "tif"
-	     "xbm" "xpm" "pbm" "pgm" "ppm")))
+	   (or extensions
+	       '("png" "jpeg" "jpg" "gif" "tiff" "tif"
+		 "xbm" "xpm" "pbm" "pgm" "ppm"))))
       (concat "\\."
       (concat "\\."
 	      (regexp-opt (nconc (mapcar 'upcase
 	      (regexp-opt (nconc (mapcar 'upcase
 					 image-file-name-extensions)
 					 image-file-name-extensions)
@@ -14179,10 +14181,10 @@ not an indirect buffer."
 			  t)
 			  t)
 	      "\\'"))))
 	      "\\'"))))
 
 
-(defun org-file-image-p (file)
+(defun org-file-image-p (file &optional extensions)
   "Return non-nil if FILE is an image."
   "Return non-nil if FILE is an image."
   (save-match-data
   (save-match-data
-    (string-match (org-image-file-name-regexp) file)))
+    (string-match (org-image-file-name-regexp extensions) file)))
 
 
 (defun org-get-cursor-date ()
 (defun org-get-cursor-date ()
   "Return the date at cursor in as a time.
   "Return the date at cursor in as a time.