[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Issue with multiline string variable for JavaScript source code
From: |
Nicolas Goaziou |
Subject: |
Re: [O] Issue with multiline string variable for JavaScript source code blocks |
Date: |
Sat, 22 Nov 2014 00:07:47 +0100 |
Hello,
Peter Moresi <address@hidden> writes:
> Sure, the patch is attached.
Applied. Thank you.
However I had to fill your commit message, which was incomplete. For
reference, here is what I used, from your initial report:
--8<---------------cut here---------------start------------->8---
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.
#+NAME: my-csv-data
#+BEGIN_EXAMPLE
ColA,ColB,ColC
1,2,3
4,5,6
#+END_EXAMPLE
I have a JavaScript function that accepts a string named 'csv' and passing in
'my-csv-data'.
#+BEGIN_SRC js :var csv=my-csv-data :results output
console.log(csv);
#+END_SRC
When I expand the source block I end up with:
#+BEGIN_SRC js
var csv="ColA,ColB,ColC
1,2,3
4,5,6";
console.log(csv);
#+END_SRC
This will not execute correctly because JavaScript does not support newlines in
strings.
What I want instead is:
#+BEGIN_SRC js
var csv="ColA,ColB,ColC\n 1,2,3\n 4,5,6";
console.log(csv);
#+END_SRC
TINYCHANGE
--8<---------------cut here---------------end--------------->8---
Regards,
--
Nicolas Goaziou