Explorar el Código

Make inline image definition more configurable

* contrib/lisp/org-element.el (org-element-object-restrictions): Allow
  plain links in link description.
* contrib/lisp/org-export.el (org-export-default-inline-image-rule):
  New variable.
(org-export-inline-image-p): Use rules instead of extensions. A rule
is a regexp applied to path for a given type of link.  It allows to
extend inline images to non-local files.
* EXPERIMENTAL/org-e-latex.el (org-e-latex-inline-image-rules): New
  variable.
(org-e-latex-inline-image-extensions): Removed variable

There are two motivations behind this change.  The first one is to
allow, for example, an HTML exporter to define a rule like the
following:

 ("http" . "\\.\\(png\\|jpg\\|jpeg\\|gif\\)\\(\\?\\(\\w+=\\w+&?\\)*\\)?")

The other one is to properly define thumbnails (clickable images),
like the following:

  [[http://orgmode.org][file:~/my-logo.png]]
Nicolas Goaziou hace 13 años
padre
commit
7d3f7f60e0
Se han modificado 3 ficheros con 52 adiciones y 20 borrados
  1. 16 11
      EXPERIMENTAL/org-e-latex.el
  2. 1 1
      contrib/lisp/org-element.el
  3. 35 8
      contrib/lisp/org-export.el

+ 16 - 11
EXPERIMENTAL/org-e-latex.el

@@ -352,17 +352,22 @@ to typeset and try to protect special characters."
   :group 'org-export-e-latex
   :type 'string)
 
-(defcustom org-e-latex-inline-image-extensions
-  '("pdf" "jpeg" "jpg" "png" "ps" "eps")
-  "Extensions of image files that can be inlined into LaTeX.
-
-Note that the image extension *actually* allowed depend on the
-way the LaTeX file is processed.  When used with pdflatex, pdf,
-jpg and png images are OK.  When processing through dvi to
-Postscript, only ps and eps are allowed.  The default we use here
-encompasses both."
+(defcustom org-e-latex-inline-image-rules
+  '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
+  "Rules characterizing image files that can be inlined into LaTeX.
+
+A rule consists in an association whose key is the type of link
+to consider, and value is a regexp that will be matched against
+link's path.
+
+Note that, by default, the image extension *actually* allowed
+depend on the way the LaTeX file is processed.  When used with
+pdflatex, pdf, jpg and png images are OK.  When processing
+through dvi to Postscript, only ps and eps are allowed.  The
+default we use here encompasses both."
   :group 'org-export-e-latex
-  :type '(repeat (string :tag "Extension")))
+  :type '(alist :key-type (string :tag "Type")
+		:value-type (regexp :tag "Path")))
 
 
 ;;;; Tables
@@ -1372,7 +1377,7 @@ INFO is a plist holding contextual information.  See
 	 ;; Ensure DESC really exists, or set it to nil.
 	 (desc (and (not (string= desc "")) desc))
 	 (imagep (org-export-inline-image-p
-		  link org-e-latex-inline-image-extensions))
+		  link org-e-latex-inline-image-rules))
 	 (path (cond
 		((member type '("http" "https" "ftp" "mailto"))
 		 (concat type ":" raw-path))

+ 1 - 1
contrib/lisp/org-element.el

@@ -2518,7 +2518,7 @@ This list is checked after translations have been applied.  See
   '((emphasis entity export-snippet inline-babel-call inline-src-block
 	      radio-target sub/superscript target text-markup time-stamp)
     (link entity export-snippet inline-babel-call inline-src-block
-	  latex-fragment sub/superscript text-markup)
+	  latex-fragment link sub/superscript text-markup)
     (radio-target entity export-snippet latex-fragment sub/superscript)
     (subscript entity export-snippet inline-babel-call inline-src-block
 	       latex-fragment sub/superscript text-markup)

+ 35 - 8
contrib/lisp/org-export.el

@@ -233,6 +233,21 @@ considered back-end.  Filters defined there will always be
 prepended to the current list, so they always get applied
 first.")
 
+(defconst org-export-default-inline-image-rule
+  `(("file" .
+     ,(format "\\.%s\\'"
+	      (regexp-opt
+	       '("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
+		 "xpm" "pbm" "pgm" "ppm") t))))
+  "Default rule for link matching an inline image.
+This rule applies to links with no description.  By default, it
+will be considered as an inline image if it targets a local file
+whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
+\"tiff\", \"tif\", \"xbm\", \"xpm\", \"pbm\", \"pgm\" or \"ppm\".
+See `org-export-inline-image-p' for more information about
+rules.")
+
+
 
 ;;; User-configurable Variables
 
@@ -2508,17 +2523,29 @@ PATH is the link path.  DESC is its description."
 	  ((string= desc "") "%s")
 	  (t desc))))
 
-(defun org-export-inline-image-p (link &optional extensions)
+(defun org-export-inline-image-p (link &optional rules)
   "Non-nil if LINK object points to an inline image.
 
-When non-nil, optional argument EXTENSIONS is a list of valid
-extensions for image files, as strings.  Otherwise, a default
-list is provided \(cf `org-image-file-name-regexp'\)."
+Optional argument is a set of RULES defining inline images.  It
+is an alist where associations have the following shape:
+
+  \(TYPE . REGEXP)
+
+Applying a rule means apply REGEXP against LINK's path when its
+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-get-contents link))
-       (string= (org-element-get-property :type link) "file")
-       (org-file-image-p
-	(expand-file-name (org-element-get-property :path link))
-	extensions)))
+       (let ((case-fold-search t)
+	     (rules (or rules org-export-default-inline-image-rule)))
+	 (some
+	  (lambda (rule)
+	    (and (string= (org-element-get-property :type link) (car rule))
+		 (string-match (cdr rule)
+			       (org-element-get-property :path link))))
+	  rules))))
 
 (defun org-export-resolve-fuzzy-link (link info)
   "Return LINK destination.