ox: Fix inline source block evaluation

* lisp/ox.el (org-export-as): Specifically expand {{{results}}} macro
  after Babel code execution.
* testing/lisp/test-ox.el (test-org-export/expand-macro): Add test.

Reported-by: "Berry, Charles" <ccberry@ucsd.edu>
<http://lists.gnu.org/r/emacs-orgmode/2017-12/msg00202.html>
This commit is contained in:
Nicolas Goaziou 2017-12-11 14:50:02 +01:00
parent 076cba6b2d
commit c3c1c52eb8
2 changed files with 17 additions and 5 deletions

View File

@ -3034,20 +3034,24 @@ Return code as a string."
;; Run first hook with current back-end's name as argument.
(run-hook-with-args 'org-export-before-processing-hook
(org-export-backend-name backend))
;; Include files, delete comments and expand macros.
;; Include files, delete comments and expand macros. Refresh
;; buffer properties and radio targets after these
;; potentially invasive changes.
(org-export-expand-include-keyword)
(org-export--delete-comment-trees)
(org-macro-initialize-templates)
(org-macro-replace-all (append org-macro-templates
org-export-global-macros)
parsed-keywords)
;; Refresh buffer properties and radio targets after
;; potentially invasive previous changes. Likewise, do it
;; again after executing Babel code.
(org-set-regexps-and-options)
(org-update-radio-target-regexp)
;; Possibly execute Babel code. Re-run a macro expansion
;; specifically for {{{results}}} since inline source blocks
;; may have generated some more. Refresh buffer properties
;; and radio targets another time.
(when org-export-use-babel
(org-babel-exp-process-buffer)
(org-macro-replace-all '(("results" . "$1")) parsed-keywords)
(org-set-regexps-and-options)
(org-update-radio-target-regexp))
;; Run last hook with current back-end's name as argument.

View File

@ -1431,7 +1431,15 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
;; Throw an error when a macro definition is missing.
(should-error
(org-test-with-temp-text "{{{missing}}}"
(org-export-as (org-test-default-backend)))))
(org-export-as (org-test-default-backend))))
;; Inline source blocks generate {{{results}}} macros. Evaluate
;; those.
(should
(equal "=2=\n"
(org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
(let ((org-export-use-babel t)
(org-babel-inline-result-wrap "=%s="))
(org-export-as (org-test-default-backend)))))))
(ert-deftest test-org-export/before-processing-hook ()
"Test `org-export-before-processing-hook'."