ソースを参照

New strip-export noweb header argument value

* lisp/ob-exp.el (org-babel-exp-src-block): Strip noweb references on
  export when "strip-export".
* lisp/ob.el (org-babel-common-header-args-w-values): New noweb
  header value.
  (org-babel-merge-params): New noweb header value.
  (org-babel-noweb-p): New noweb header value.
* testing/examples/babel.org (an): Testing new noweb header value.
* testing/lisp/test-ob-exp.el (ob-exp/noweb-strip-export-ensure-strips):
  Testing new noweb header value.
* doc/org.texi (noweb): Document new noweb header value.
Eric Schulte 13 年 前
コミット
a3e5f97ee7
5 ファイル変更43 行追加11 行削除
  1. 6 2
      doc/org.texi
  2. 7 4
      lisp/ob-exp.el
  3. 7 5
      lisp/ob.el
  4. 14 0
      testing/examples/babel.org
  5. 9 0
      testing/lisp/test-ob-exp.el

+ 6 - 2
doc/org.texi

@@ -13609,8 +13609,8 @@ interpreted language.
 The @code{:noweb} header argument controls expansion of ``noweb'' syntax
 references (see @ref{Noweb reference syntax}) when the code block is
 evaluated, tangled, or exported.  The @code{:noweb} header argument can have
-one of four values: @code{no}, @code{yes}, @code{tangle}, or
-@code{no-export}.
+one of the five values: @code{no}, @code{yes}, @code{tangle}, or
+@code{no-export} @code{strip-export}.
 
 @itemize @bullet
 @item @code{no}
@@ -13627,6 +13627,10 @@ not be expanded when the code block is evaluated or exported.
 ``Noweb'' syntax references in the body of the code block will be expanded
 before the block is evaluated or tangled. However, ``noweb'' syntax
 references will not be expanded when the code block is exported.
+@item @code{strip-export}
+``Noweb'' syntax references in the body of the code block will be expanded
+before the block is evaluated or tangled. However, ``noweb'' syntax
+references will not be removed when the code block is exported.
 @end itemize
 
 @subsubheading Noweb prefix lines

+ 7 - 4
lisp/ob-exp.el

@@ -109,10 +109,13 @@ none ----- do not display either code or results upon export"
 	  (setf hash (org-babel-sha1-hash info)))
 	;; expand noweb references in the original file
 	(setf (nth 1 info)
-	      (if (org-babel-noweb-p (nth 2 info) :export)
-		  (org-babel-expand-noweb-references
-		   info (get-file-buffer org-current-export-file))
-		(nth 1 info)))
+	      (if (string= "strip-export" (cdr (assoc :noweb (nth 2 info))))
+		  (replace-regexp-in-string
+		   (org-babel-noweb-wrap) "" (nth 1 info))
+		(if (org-babel-noweb-p (nth 2 info) :export)
+		    (org-babel-expand-noweb-references
+		     info (get-file-buffer org-current-export-file))  
+		  (nth 1 info))))
 	(org-babel-exp-do-export info 'block hash)))))
 
 (defcustom org-babel-exp-call-line-template

+ 7 - 5
lisp/ob.el

@@ -398,7 +398,7 @@ then run `org-babel-pop-to-session'."
     (mkdirp	. ((yes no)))
     (no-expand)
     (noeval)
-    (noweb	. ((yes no tangle)))
+    (noweb	. ((yes no tangle no-export strip-export)))
     (noweb-ref	. :any)
     (noweb-sep  . :any)
     (padline	. ((yes no)))
@@ -2086,8 +2086,10 @@ parameters when merging lists."
 	      (:tangle ;; take the latest -- always overwrite
 	       (setq tangle (or (list (cdr pair)) tangle)))
 	      (:noweb
-	       (setq noweb (e-merge '(("yes" "no" "tangle" "no-export")) noweb
-				    (split-string (or (cdr pair) "")))))
+	       (setq noweb (e-merge
+			    '(("yes" "no" "tangle" "no-export" "strip-export"))
+			    noweb
+			    (split-string (or (cdr pair) "")))))
 	      (:cache
 	       (setq cache (e-merge '(("yes" "no")) cache
 				    (split-string (or (cdr pair) "")))))
@@ -2128,8 +2130,8 @@ CONTEXT may be one of :tangle, :export or :eval."
 			     (car as)
 			   (intersect (cdr as) bs)))))
     (intersect (case context
-                    (:tangle '("yes" "tangle" "no-export"))
-                    (:eval   '("yes" "no-export"))
+                    (:tangle '("yes" "tangle" "no-export" "strip-export"))
+                    (:eval   '("yes" "no-export" "strip-export"))
                     (:export '("yes")))
                   (split-string (or (cdr (assoc :noweb params)) "")))))
 

+ 14 - 0
testing/examples/babel.org

@@ -341,3 +341,17 @@ Fifth
   :END:
 Here is a call line with more than just the results exported.
 #+call: double(8)
+* strip noweb references on export
+  :PROPERTIES:
+  :ID:       8e7bd234-99b2-4b14-8cd6-53945e409775
+  :END:
+
+#+name: strip-export-1
+#+BEGIN_SRC sh :exports none
+  i="10"
+#+END_SRC
+
+#+BEGIN_SRC sh :noweb strip-export :exports code :results silent
+  <<strip-export-1>>
+  echo "1$i"
+#+END_SRC

+ 9 - 0
testing/lisp/test-ob-exp.el

@@ -240,6 +240,15 @@ elements in the final html."
       (should (string-match "16" html))
       (should (string-match "special-token" html)))))
 
+(ert-deftest ob-exp/noweb-strip-export-ensure-strips ()
+  (org-test-at-id "8e7bd234-99b2-4b14-8cd6-53945e409775"
+    (org-narrow-to-subtree)
+    (org-babel-next-src-block 2)
+    (should (= 110 (org-babel-execute-src-block)))
+    (let ((ascii (org-export-as-ascii nil nil nil 'string t)))
+      (should-not (string-match (regexp-quote "<<strip-export-1>>") ascii))
+      (should-not (string-match (regexp-quote "i=\"10\"") ascii)))))
+
 (provide 'test-ob-exp)
 
 ;;; test-ob-exp.el ends here