emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Issue with multiline string variable for JavaScript source code


From: Peter Moresi
Subject: Re: [O] Issue with multiline string variable for JavaScript source code blocks
Date: Fri, 21 Nov 2014 16:12:26 -0800

Excellent and thanks for the feedback. I'm glad I was able to give something back to the community that has given me so much.

I've also had issues with _javascript_ source code blocks truncating the result when the value is a string with a comma. I'm still getting up to speed with Emacs-lisp but when I figure out how to fix the issue I will send the patch with proper comments.

Thanks,
Peter

On Friday, November 21, 2014, Nicolas Goaziou <address@hidden> wrote:
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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]