From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Moresi Subject: Re: Issue with multiline string variable for JavaScript source code blocks Date: Fri, 21 Nov 2014 16:12:26 -0800 Message-ID: References: <87bno4fb8j.fsf@nicolasgoaziou.fr> <87wq6o40fw.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e01495424963c060508676af2 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XryJR-0005GO-3j for emacs-orgmode@gnu.org; Fri, 21 Nov 2014 19:12:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XryJP-000325-VQ for emacs-orgmode@gnu.org; Fri, 21 Nov 2014 19:12:29 -0500 Received: from mail-ie0-x232.google.com ([2607:f8b0:4001:c03::232]:60044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XryJP-00031X-Ow for emacs-orgmode@gnu.org; Fri, 21 Nov 2014 19:12:27 -0500 Received: by mail-ie0-f178.google.com with SMTP id tp5so5835646ieb.23 for ; Fri, 21 Nov 2014 16:12:26 -0800 (PST) In-Reply-To: <87wq6o40fw.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Peter Moresi , "emacs-orgmode@gnu.org" --089e01495424963c060508676af2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 wrote: > Hello, > > Peter Moresi > writes: > > > Sure, the patch is attached.=E2=80=8B > > 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 passin= g > in 'my-csv-data'. > > #+BEGIN_SRC js :var csv=3Dmy-csv-data :results output > console.log(csv); > #+END_SRC > > When I expand the source block I end up with: > > #+BEGIN_SRC js > var csv=3D"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=3D"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 > --089e01495424963c060508676af2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Excellent and=C2=A0thanks for the feedback.=C2=A0I'm glad I was ab= le to give something back to the community that has given me so much.
=

I've also had=C2=A0issues with JavaScript source co= de blocks truncating the result when the value is a=C2=A0string with a=C2= =A0comma. I'm still getting up to speed with Emacs-lisp but when=C2=A0I= figure out how to fix the issue=C2=A0I will send the patch with proper com= ments.

Thanks,
Peter
<= div>

On Friday, November 21, 2014, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrot= e:
Hello,

Peter Moresi <peter.moresi@gmail.com> write= s:

> Sure, the patch is attached.=E2=80=8B

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
=C2=A0 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
=C2=A0 ColA,ColB,ColC
=C2=A0 1,2,3
=C2=A0 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=3Dmy-csv-data :results output
=C2=A0 console.log(csv);
#+END_SRC

When I expand the source block I end up with:

#+BEGIN_SRC js
var csv=3D"ColA,ColB,ColC
=C2=A0 1,2,3
=C2=A0 4,5,6";
console.log(csv);
#+END_SRC

This will not execute correctly because JavaScript does not support newline= s in strings.

What I want instead is:

#+BEGIN_SRC js
=C2=A0 var csv=3D"ColA,ColB,ColC\n=C2=A0 1,2,3\n=C2=A0 4,5,6"; =C2=A0 console.log(csv);
#+END_SRC

TINYCHANGE
--8<---------------cut here---------------end--------------->8---


Regards,

--
Nicolas Goaziou
--089e01495424963c060508676af2--