From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: including external file in src block execution; ATTR_HTML on src blocks Date: Mon, 12 Dec 2016 15:53:04 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11452d1449063405437c4a25 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGXbv-0002wA-Av for emacs-orgmode@gnu.org; Mon, 12 Dec 2016 15:54:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGXbq-0004zp-JI for emacs-orgmode@gnu.org; Mon, 12 Dec 2016 15:54:11 -0500 Received: from mail-io0-f178.google.com ([209.85.223.178]:33442) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cGXbq-0004zh-Ca for emacs-orgmode@gnu.org; Mon, 12 Dec 2016 15:54:06 -0500 Received: by mail-io0-f178.google.com with SMTP id d9so189545721ioe.0 for ; Mon, 12 Dec 2016 12:54:06 -0800 (PST) In-Reply-To: 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" Cc: Org Mode --001a11452d1449063405437c4a25 Content-Type: text/plain; charset=UTF-8 On Mon, Dec 12, 2016 at 12:16 PM, Charles C. Berry wrote: > On Mon, 12 Dec 2016, Matt Price wrote: > > > [snip] > > >> My questions are: >> 1. can I pass this html attribute to the
 block somehow?
>>
>
> Yes.
>
> ATTR_HTML doesn't seem to work.  Is this a bug? If so, should I try to fix
>> it?
>>
>
> No and no.
>
> Did you try
>
> : (plist-get (cadr src-block) :attr_html)
>
> in `org-html-src-block' ?
>
>
ah, ok.  Now I will reveal some of the depths of my ignorance.  Looks like
:attr_html is a plist (right?).
(a) what is the appropriate way to identify an attribute here.  should I
write, e.g.:

#+ATTR_HTML: :data-external-libs "http://underscorejs.org/underscore-min.js"
:class "list of classes"
or:
 #+ATTR_HTML: data-external-libs "http://underscorejs.org/underscore-min.js"
class "list of classes"
or
#+ATTR_HTML: "data-external-libs" "http://underscorejs.org/underscore-min.js"
"class" "list of classes"

And then, if I want to transform this into:

data-external-libs="http://underscorejs.org/underscore-min.js" class="list
of classes"

can I just do something like:
(let ((attributes (org-export-get-attribute :attr_html src-block))
  (cl-loop for (key value) in attributes
    (collect (concat key "=" "\"" value "\" " ))))

or do I need to transform the key into a string first?
I'm sorry to be writing such basic lisp questions; obviously I need to read
a really good lisp introduction, but I haven't found one yet.

>
> If not, is there a simple way to use header arguments to pass
>> information down?
>>
>
> The answer is still no. ;-)
>
> There are complicated ways. See
>
> https://github.com/chasberry/orgmode-accessories/blob/ravel-
> lang/ox-ravel.org
>
> for one such. But for what you are doing ATTR_HTML is easiest.
>
> I will take the easiest please!

>
> I am already rewriting the exporter's src-block export
>> function, so I can try to accomplish what I need to in that context.
>>
>
> BTW, the cleanest way to do this is by writing a derived exporter:
>
> :  (org-export-define-derived-backend 'reveal 'revealplus ...
>
> In your case you only provide the src-block entry for the
> :translate-alist, :options-alist entries for any you redefine or introduce,
> and optionally a :menu-entry.
>
> Also, you'll probably want to add a hook to `org-export-before-parsing-hook'
> (see below).
>
>
> If you do this, then `#+ATTR_REVEALPLUS:' seems suitable.
>

right. Up till now I have been hoping to integrate these change sback into
ox-reveal, but now it's starting to feel a bit invasive.  I may try this
route.

>
> 2. I'd like to be able to test my code directly in org (since I'm a lousy
>> coder and a clumsy typist). Can I tell org to load other files before
>> executing a src block?
>>
>
> Yes. Depending on what you want one of these:
>
> * Add this to `org-export-before-parsing-hook', perhaps in setting up a
>   derived exporter.
>
> * Or perhaps by using a local variable `eval' see
>
> : (info "(emacs) Specifying File Variables")
>
> * Or by executing a src-block that loads those files.
>

I think this might be the best route, since I would probably want to load
such files on a block-by-block basis.

>
> HTH,
>
> Chuck
>
very much, I think!

--001a11452d1449063405437c4a25
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Mon, Dec 12, 2016 at 12:16 PM, Charles C. Berry &l= t;ccberry@ucsd.edu> wrote:
On= Mon, 12 Dec 2016, Matt Price wrote:


[snip]


My questions are:
1. can I pass this html attribute to the <pre><code> block some= how?

Yes.

ATTR_HTML doesn't seem to work.=C2=A0 Is this a bug? If so, should I tr= y to fix
it?

No and no.

Did you try

: (plist-get (cadr src-block) :attr_html)

in `org-html-src-block' ?


ah, ok.=C2=A0 Now I will reveal= some of the depths of my ignorance.=C2=A0 Looks like :attr_html is a plist= (right?).=C2=A0
(a) what is the appropriate way to identify= an attribute here.=C2=A0 should I write, e.g.:
or:
=C2=A0#+ATTR_HTML: data-external-libs "http://underscorejs.org/underscore-min.js= " class "list of classes"
or
#+ATTR_HTML: "= ;data-external-libs" "http://un= derscorejs.org/underscore-min.js" "class" "list of = classes"

And then, if I want to transform this into:
data-external-libs= =3D"http://underscorejs.org/undersco= re-min.js" class=3D"list of classes"

can I just do something lik= e:
(let ((at= tributes (org-export-get-attribute :attr_html src-block))
=C2=A0 (cl-loo= p for (key value) in attributes
=C2=A0=C2=A0=C2=A0 (collect (concat key "=3D"= "\"" value "\" " ))))

<= /div>
or do I need to transform the = key into a string first?
I'm sorry to be writing such basic lisp questions; obvious= ly I need to read a really good lisp introduction, but I haven't found = one yet.=C2=A0

If not, is there a simple way to use header arguments to pass
information down?

The answer is still no. ;-)

There are complicated ways. See

https://github.com/chas= berry/orgmode-accessories/blob/ravel-lang/ox-ravel.org

for one such. But for what you are doing ATTR_HTML is easiest.

I will take the easiest please!

I am already rewriting the exporter's src-block export
function, so I can try to accomplish what I need to in that context.

BTW, the cleanest way to do this is by writing a derived exporter:

:=C2=A0 (org-export-define-derived-backend 'reveal 'revealplus= ...

In your case you only provide the src-block entry for the :translate-alist,= :options-alist entries for any you redefine or introduce, and optionally a= :menu-entry.

Also, you'll probably want to add a hook to `org-export-before-parsing-= hook' (see below).


If you do this, then `#+ATTR_REVEALPLUS:' seems suitable.

right. Up till now I h= ave been hoping to integrate these change sback into ox-reveal, but now it&= #39;s starting to feel a bit invasive.=C2=A0 I may try this route. =C2=A0 <= br>

2. I'd like to be able to test my code directly in org (since I'm a= lousy
coder and a clumsy typist). Can I tell org to load other files before
executing a src block?

Yes. Depending on what you want one of these:

* Add this to `org-export-before-parsing-hook', perhaps in setting= up a
=C2=A0 derived exporter.

* Or perhaps by using a local variable `eval' see

: (info "(emacs) Specifying File Variables")

* Or by executing a src-block that loads those files.
=
I think this might be the best route, since I would probably= want to load such files on a block-by-block basis. =C2=A0

HTH,

Chuck
very much, I think!
--001a11452d1449063405437c4a25--