diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index c115cf9c1..ec8a0c27a 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -86,10 +86,15 @@ Where clue > 0 [[http://plantuml.com/][Plantuml]] source blocks now support the [[http://orgmode.org/manual/prologue.html#prologue][~:prologue~]], [[http://orgmode.org/manual/epilogue.html#epilogue][~:epilogue~]] and [[http://orgmode.org/manual/var.html#var][~:var~]] header arguments. +*** Export +**** Implement ~org-export-insert-image-links~ +This new function is meant to be used in back-ends supporting images +as descriptions of links, a.k.a. image links. See its docstring for +details. +**** Horizontal rules are no longer ignored in LaTeX table math mode *** New variable : ~org-bibtex-headline-format-function~ This allow to use a different title than entry title. -*** Horizontal rules are no longer ignored in LaTeX table math mode ** Removed functions diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 63a8c847a..eb728dfa1 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -101,6 +101,7 @@ (verbatim . org-html-verbatim) (verse-block . org-html-verse-block)) :filters-alist '((:filter-options . org-html-infojs-install-script) + (:filter-parse-tree . org-html-image-link-filter) (:filter-final-output . org-html-final-function)) :menu-entry '(?h "Export to HTML" @@ -2835,6 +2836,9 @@ CONTENTS is nil. INFO is a plist holding contextual information." ;;;; Link +(defun org-html-image-link-filter (data _backend info) + (org-export-insert-image-links data info org-html-inline-image-rules)) + (defun org-html-inline-image-p (link info) "Non-nil when LINK is meant to appear as an image. INFO is a plist used as a communication channel. LINK is an diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 74969e4c4..9881cd849 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -101,7 +101,8 @@ (org-open-file (org-latex-export-to-pdf nil s v b))))))) :filters-alist '((:filter-options . org-latex-math-block-options-filter) (:filter-parse-tree org-latex-math-block-tree-filter - org-latex-matrices-tree-filter)) + org-latex-matrices-tree-filter + org-latex-image-link-filter)) :options-alist '((:latex-class "LATEX_CLASS" nil org-latex-default-class t) (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t) @@ -724,7 +725,8 @@ environment." :safe #'stringp) (defcustom org-latex-inline-image-rules - '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\|pgf\\|svg\\)\\'")) + `(("file" . ,(regexp-opt + '("pdf" "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg")))) "Rules characterizing image files that can be inlined into LaTeX. A rule consists in an association whose key is the type of link @@ -2268,6 +2270,9 @@ CONTENTS is nil. INFO is a plist holding contextual information." ;;;; Link +(defun org-latex-image-link-filter (data _backend info) + (org-export-insert-image-links data info org-latex-inline-image-rules)) + (defun org-latex--inline-image (link info) "Return LaTeX code for an inline image. LINK is the link pointing to the inline image. INFO is a plist diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el index 24658363c..92c54cf8d 100644 --- a/lisp/ox-odt.el +++ b/lisp/ox-odt.el @@ -85,7 +85,8 @@ :filters-alist '((:filter-parse-tree . (org-odt--translate-latex-fragments org-odt--translate-description-lists - org-odt--translate-list-tables))) + org-odt--translate-list-tables + org-odt--translate-image-links))) :menu-entry '(?o "Export to ODT" ((?o "As ODT file" org-odt-export-to-odt) @@ -3687,6 +3688,11 @@ contextual information." ;;; Filters +;;; Images + +(defun org-odt--translate-image-links (data _backend info) + (org-export-insert-image-links data info inline image rules)) + ;;;; LaTeX fragments (defun org-odt--translate-latex-fragments (tree _backend info) diff --git a/lisp/ox.el b/lisp/ox.el index 4adfd743e..5e361792f 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -4160,12 +4160,55 @@ the provided rules is non-nil. The default rule is This only applies to links without a description." (and (not (org-element-contents link)) (let ((case-fold-search t)) - (catch 'exit - (dolist (rule (or rules org-export-default-inline-image-rule)) - (and (string= (org-element-property :type link) (car rule)) - (string-match-p (cdr rule) - (org-element-property :path link)) - (throw 'exit t))))))) + (cl-some (lambda (rule) + (and (string= (org-element-property :type link) (car rule)) + (string-match-p (cdr rule) + (org-element-property :path link)))) + (or rules org-export-default-inline-image-rule))))) + +(defun org-export-insert-image-links (data info &optional rules) + "Insert image links in DATA. + +Org syntax do not support nested links. Nevertheless, some +export back-ends support image as descriptions of links. Since +images are really link to image files, we need to make an +exception about link nesting. + +This function recognizes links whose contents are really images +and turn them into proper nested links. It is meant to be used +as a parse tree filter in back-ends supporting such constructs. + +DATA is a parse tree. INFO is the current state of the export +process, as a plist. + +A description is a valid images if it matches any rule in RULES, +if non-nil, or `org-export-default-inline-image-rule' otherwise. +See `org-export-inline-image-p' for more information about the +structure of RULES. + +Return modified DATA." + (let ((link-re (format "\\`\\(?:%s\\|%s\\)\\'" + org-plain-link-re + org-angle-link-re)) + (case-fold-search t)) + (org-element-map data 'link + (lambda (l) + (let ((contents (org-element-interpret-data (org-element-contents l)))) + (when (and (org-string-nw-p contents) + (string-match link-re contents)) + (let ((type (match-string 1 contents)) + (path (match-string 2 contents))) + (when (cl-some (lambda (rule) + (and (string= type (car rule)) + (string-match-p (cdr rule) path))) + (or rules org-export-default-inline-image-rule)) + (org-element-set-contents + l + (with-temp-buffer + (save-excursion (insert contents)) + (org-element-link-parser)))))))) + info nil nil t)) + data) (defun org-export-resolve-coderef (ref info) "Resolve a code reference REF.