From aa65ac35aa4c82cf4db9d5bc6bff55afb3a9089b Mon Sep 17 00:00:00 2001 From: Peter Moresi Date: Tue, 18 Nov 2014 15:58:17 -0800 Subject: [PATCH] ob-js: Fix passing multiline variables * lisp/ob-js.el (org-babel-js-var-to-js): Replace newline characters with "\n" in strings. Let's say I have a multi-line string stored in an example block. I want to store my CSV in an example block. ColA,ColB,ColC 1,2,3 4,5,6 I have a JavaScript function that accepts a string named 'csv' and passing in 'my-csv-data'. console.log(csv); When I expand the source block I end up with: var csv="ColA,ColB,ColC 1,2,3 4,5,6"; console.log(csv); This will not execute correctly because JavaScript does not support newlines in strings. What I want instead is: var csv="ColA,ColB,ColC\n 1,2,3\n 4,5,6"; console.log(csv); TINYCHANGE --- lisp/ob-js.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ob-js.el b/lisp/ob-js.el index 7789449a9..ea51ed983 100644 --- a/lisp/ob-js.el +++ b/lisp/ob-js.el @@ -113,7 +113,7 @@ Convert an elisp value into a string of js source code specifying a variable of the same value." (if (listp var) (concat "[" (mapconcat #'org-babel-js-var-to-js var ", ") "]") - (format "%S" var))) + (replace-regexp-in-string "\n" "\\\\n" (format "%S" var)))) (defun org-babel-prep-session:js (session params) "Prepare SESSION according to the header arguments specified in PARAMS."