emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* including external file in src block execution; ATTR_HTML on src blocks
@ 2016-12-12 14:12 Matt Price
  2016-12-12 17:16 ` Charles C. Berry
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Price @ 2016-12-12 14:12 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 972 bytes --]

I use org to write my lecture notes, and have started using klipse in those
exported notes to execute code snippets in a browser environment (
http://matt.hackinghistory.ca/2016/12/11/org-mode-run-code-live-in-a-reveal-slideshow-with-klipse/
). Sometimes I would like to set up the javascript environment with some
additional libraries, either local or web-based. Klipse lets you do this
with a custom data- attribute.

My questions are:
1. can I pass this html attribute to the <pre><code> block somehow?
ATTR_HTML doesn't seem to work.  Is this a bug? If so, should I try to fix
it? If not, is there a simple way to use header arguments to pass
information down? I am already rewriting the exporter's src-block export
function, so I can try to accomplish what I need to in that context.
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?

Thank you!
Mat

[-- Attachment #2: Type: text/html, Size: 1248 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: including external file in src block execution; ATTR_HTML on src blocks
  2016-12-12 14:12 including external file in src block execution; ATTR_HTML on src blocks Matt Price
@ 2016-12-12 17:16 ` Charles C. Berry
  2016-12-12 20:53   ` Matt Price
  0 siblings, 1 reply; 6+ messages in thread
From: Charles C. Berry @ 2016-12-12 17:16 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

On Mon, 12 Dec 2016, Matt Price wrote:


[snip]

>
> My questions are:
> 1. can I pass this html attribute to the <pre><code> 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' ?


> 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 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.

> 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.

HTH,

Chuck

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: including external file in src block execution; ATTR_HTML on src blocks
  2016-12-12 17:16 ` Charles C. Berry
@ 2016-12-12 20:53   ` Matt Price
  2016-12-13  3:52     ` Charles C. Berry
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Price @ 2016-12-12 20:53 UTC (permalink / raw)
  Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 3221 bytes --]

On Mon, Dec 12, 2016 at 12:16 PM, Charles C. Berry <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 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!

[-- Attachment #2: Type: text/html, Size: 7154 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: including external file in src block execution; ATTR_HTML on src blocks
  2016-12-12 20:53   ` Matt Price
@ 2016-12-13  3:52     ` Charles C. Berry
       [not found]       ` <CAN_Dec8=72-TvAGD82=tKLPUEO6qD4Mub4RV-hXUrVReHDqRyQ@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Charles C. Berry @ 2016-12-13  3:52 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

On Mon, 12 Dec 2016, Matt Price wrote:

> On Mon, Dec 12, 2016 at 12:16 PM, Charles C. Berry <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 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?).

No, it is a property name. (cadr src-block) is the plist.

See (info "(elisp) Property Lists")


> (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"

Any could be made to work, but I'd use (a). Then

: (org-babel-parse-header-arguments
:  (car (plist-get (cadr src-block) :attr_html)))

will give you

: ((: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?

Well, I'd just try it and see.

> 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.
>

This is what I use:

* Elisp: (elisp).               The Emacs Lisp Reference Manual.
* Emacs Lisp Intro: (eintr).    A simple introduction to Emacs Lisp programming.

and ample Googling, usually leading to StackOverflow, to get hints on 
stuff I am fuzzy on. And I read docstrings over and over and ...

Best,

Chuck

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Fwd: including external file in src block execution; ATTR_HTML on src blocks
       [not found]       ` <CAN_Dec8=72-TvAGD82=tKLPUEO6qD4Mub4RV-hXUrVReHDqRyQ@mail.gmail.com>
@ 2016-12-13 14:44         ` Matt Price
  2016-12-14  4:08           ` Charles C. Berry
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Price @ 2016-12-13 14:44 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 4009 bytes --]

(sent to Charles direcly by mistake. Charles, this resend gave me the
chance to modify my response)
On Mon, Dec 12, 2016 at 10:52 PM, Charles C. Berry <ccberry@ucsd.edu> wrote:

> On Mon, 12 Dec 2016, Matt Price wrote:
>
> On Mon, Dec 12, 2016 at 12:16 PM, Charles C. Berry <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 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?).
>>
>
> No, it is a property name. (cadr src-block) is the plist.
>

:-)  I think what I meant was, looks like (org-export-read-attribute
:attr_html src-block) RETURNS a plist.  But that doesn't seem to be quite
true, if I'm understanding properly what a plist is.

Instead it returns a list of this form:
(:code_attribs data-external-libs="https://cdnjs.cloudflare.com/ajax/
libs/jquery/3.1.1/jquery.js" data-other="other" :class some class list)

 Access to the :properties only seems reliable through
(org-export-read-attribute :attr_html src_plock :propname), which returns
what should be an odd list of symbols (?) as a string. Again, it seems
somewhat mysterious to me.

UPDATE: despite the tentative solution seen below, I guess maybe the
#+ATTR_XXX attributes are not intended for iteration as I describe, but
instead each such attribute should have a well-specified function that the
exporter knows about.  If I'm adding attributes -- and it turns out that
ox-reveal can interpret a :code_attribs attribute that I hadn't known about
-- then I feel like I should structure them in an expected way.  I haven't
found documentation about the best practice here and would definitely
appreciate further pointers.


> See (info "(elisp) Property Lists")
>
>
> (a) what is the appropriate way to identify an attribute here.  should I
>> write, e.g.:
>>
>> #+ATTR_HTML: :data-external-libs "http://underscorejs.org/under
>> score-min.js"
>> :class "list of classes"
>>
>
> Any could be made to work, but I'd use (a). Then
>
> : (org-babel-parse-header-arguments
> :  (car (plist-get (cadr src-block) :attr_html)))
>
> will give you
>
> : ((:data-external-libs . "http://underscorejs.org/underscore-min.js") :
>  (:class . "list of classes"))
>

ah, ok, thank you.   Someday I hope I really understand list objects and
how to transform them.  I think part of the problem is that, unlike in some
other languages, programming effectively requires a proper understanding of
*what the objects are that you're manipulating*, and I'm just a bit too
stupid to learn this effectively on my own.

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?
>>
>
> Well, I'd just try it and see.
>
:-) Seems like I should be able to manage this now!


> 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.
>>
>>
> This is what I use:
>
> * Elisp: (elisp).               The Emacs Lisp Reference Manual.
> * Emacs Lisp Intro: (eintr).    A simple introduction to Emacs Lisp
> programming.
>
> and ample Googling, usually leading to StackOverflow, to get hints on
> stuff I am fuzzy on. And I read docstrings over and over and ...
>

This is the method i'm using, but for me it's veeeeerrrrry slow.



>
> Best,
>
> Chuck
>

Thank you Chuck!

[-- Attachment #2: Type: text/html, Size: 7505 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fwd: including external file in src block execution; ATTR_HTML on src blocks
  2016-12-13 14:44         ` Fwd: " Matt Price
@ 2016-12-14  4:08           ` Charles C. Berry
  0 siblings, 0 replies; 6+ messages in thread
From: Charles C. Berry @ 2016-12-14  4:08 UTC (permalink / raw)
  To: Matt Price; +Cc: Org Mode

On Tue, 13 Dec 2016, Matt Price wrote:

> (sent to Charles direcly by mistake. Charles, this resend gave me the
> chance to modify my response)
> On Mon, Dec 12, 2016 at 10:52 PM, Charles C. Berry <ccberry@ucsd.edu> wrote:

[snipping throughout]

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


>>>> : (plist-get (cadr src-block) :attr_html)
>>>>
>>>> in `org-html-src-block' ?
>>>>


>
> :-)  I think what I meant was, looks like (org-export-read-attribute
> :attr_html src-block) RETURNS a plist.  But that doesn't seem to be quite
> true, if I'm understanding properly what a plist is.
>

It looks to me like `org-export-read-attribute' reliably returns a
plist when used with three args.

> Instead it returns a list of this form:
> (:code_attribs data-external-libs="https://cdnjs.cloudflare.com/ajax/
> libs/jquery/3.1.1/jquery.js" data-other="other" :class some class list)

That isn't a plist. I don't believe that `org-export-read-attribute'
gave you that. Maybe you dropped some quotes? Do you have an ECM that
shows that behavior?

>
> Access to the :properties only seems reliable through
> (org-export-read-attribute :attr_html src_plock :propname), which returns
> what should be an odd list of symbols (?) as a string. Again, it seems
> somewhat mysterious to me.

You lost me here. I don't know what `src_plock' contains, so I can't
really say whether what that returns makes sense or not.

Chuck

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-14  4:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-12 14:12 including external file in src block execution; ATTR_HTML on src blocks Matt Price
2016-12-12 17:16 ` Charles C. Berry
2016-12-12 20:53   ` Matt Price
2016-12-13  3:52     ` Charles C. Berry
     [not found]       ` <CAN_Dec8=72-TvAGD82=tKLPUEO6qD4Mub4RV-hXUrVReHDqRyQ@mail.gmail.com>
2016-12-13 14:44         ` Fwd: " Matt Price
2016-12-14  4:08           ` Charles C. Berry

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).