* Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html'
@ 2012-09-24 6:34 thorne
2012-09-24 21:53 ` thorne
0 siblings, 1 reply; 6+ messages in thread
From: thorne @ 2012-09-24 6:34 UTC (permalink / raw)
To: emacs-orgmode
Can I use babel to generate html to be exported in a #+BEGIN_HTML
... section using `org-export-region-as-html'? I ask because the
behaviour I am seeing is different depending on whether I use that
function or `org-export-as-html'. The former function exports
the html code to show the html code, whereas the later exports
the html code directly as html.
To concretize that a bit, I have a pair of functions that look
like this (have I misunderstood they way the export is supposed
to work?) --
(defun embed-pdf-function (pdf-file)
(concat "<iframe src=\"http://docs.google.com/gview?url=http://example.net/"
pdf-file
"&embedded=true\" style=\"width:25em; height:38em;\"
frameborder=\"0\"></iframe>\n"))
(defun embed-pdf (pdf-file)
(interactive "MFile name: ")
(insert (concat
"#+BEGIN_SRC emacs-lisp :exports results :results html\n"
"(embed-pdf-function \"" pdf-file "\")\n"
"#+END_SRC")))
When I call the first in an org buffer and give it "foo.pdf" as
an argument, it inserts something that looks like this:
#+BEGIN_SRC emacs-lisp :exports results :results html
(embed-pdf-function "foo.pdf")
#+END_SRC
When I use `org-export-as-html' in that buffer I end up with an
html file that includes this, which IS what I would want:
<iframe src="http://docs.google.com/gview?url=http://example.net/foo.pdf&embedded=true"
style="width:25em; height:38em;" frameborder="0"></iframe>
But, when I instead use `org-export-region-as-html' in a
program (because I am hoping to get the results as a string,
rather than in a buffer) using something like this --
(org-export-region-as-html (point-min) (point-max) t 'string)
-- the result I get in the html looks like this:
<pre class="example">
<iframe src="http://docs.google.com/gview?url=http://example.net/foo.pdf&embedded=true"
style="width:25em; height:38em;" frameborder="0"></iframe>
</pre>
Which of course is not the iframe I was hoping for, but is the
code to render the code for it in html.
Should the region export function work the way I am hoping at
all? -- can it be made to do so?
(
I also have the following set globally, if it is relevant:
(setq org-confirm-babel-evaluate nil)
(setq org-export-babel-evaluate t)
and --
M-x org-version RET ==> "Org-mode version 7.8.11"
)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html'
2012-09-24 6:34 Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html' thorne
@ 2012-09-24 21:53 ` thorne
2012-09-25 1:24 ` Bastien
2012-09-25 6:05 ` thorne
0 siblings, 2 replies; 6+ messages in thread
From: thorne @ 2012-09-24 21:53 UTC (permalink / raw)
To: emacs-orgmode
Actually I think I have a simpler version of this question now.
I have this function:
(defun render-one (file)
(with-temp-buffer
(insert-file file)
(org-export-as-html nil nil nil 'string t)))
With the last line being the important bit.
If I open a file, foo.org, that has the #+BEING_SRC bit that I
want to export, and put this line in the buffer and evaluate it:
(org-export-as-html nil nil nil 'string t)
then the result I get is correct -- the html that I want is
embedded in the resulting string. But if instead I evaluate
(render-one "~/foo.org")
using the function above which should (I assume) do the same
thing, it does not work. Instead, the html code I want is
wrapped in <pre> tags and angle brackets changed to html
entities.
So, it seems that something about running the export function in
my code above makes it ignore my :results html setting in the
code block. Is this a security thing? Is there a variable that
I need to let-bind in my function or something?
Thanks for any help.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html'
2012-09-24 21:53 ` thorne
@ 2012-09-25 1:24 ` Bastien
2012-09-25 6:05 ` thorne
1 sibling, 0 replies; 6+ messages in thread
From: Bastien @ 2012-09-25 1:24 UTC (permalink / raw)
To: thorne; +Cc: emacs-orgmode
thorne <ego111@gmail.com> writes:
> (defun render-one (file)
> (with-temp-buffer
> (insert-file file)
> (org-export-as-html nil nil nil 'string t)))
Try
(defun render-one (file)
(with-temp-buffer
(insert-file file)
(org-mode)
(org-export-as-html nil nil nil 'string t)))
(org-mode) is important here.
--
Bastien
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html'
2012-09-24 21:53 ` thorne
2012-09-25 1:24 ` Bastien
@ 2012-09-25 6:05 ` thorne
2012-09-25 9:13 ` Bastien
1 sibling, 1 reply; 6+ messages in thread
From: thorne @ 2012-09-25 6:05 UTC (permalink / raw)
To: emacs-orgmode
On Mon, Sep 24, 2012 at 3:53 PM, thorne <ego111@gmail.com> wrote:
> (defun render-one (file)
> (with-temp-buffer
> (insert-file file)
> (org-export-as-html nil nil nil 'string t)))
Well, I still don't know why it behaves the way I've described, but it
works the way I want if instead of the above function, I use:
(defun render-one (file)
(save-excursion
(let ((buffer (set-buffer (find-file file))))
(setq rtn (org-export-as-html nil nil nil 'string t))
(kill-buffer buffer)
rtn)))
-- using find-file and messing with the buffer stuff by hand, instead
of using `with-temp-buffer' and `insert-file', which later strikes me
as neater, and possibly faster (I am using it in batch to process
multiple files) but the other way works, so that's fine. Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html'
2012-09-25 6:05 ` thorne
@ 2012-09-25 9:13 ` Bastien
2012-09-26 7:28 ` thorne
0 siblings, 1 reply; 6+ messages in thread
From: Bastien @ 2012-09-25 9:13 UTC (permalink / raw)
To: thorne; +Cc: emacs-orgmode
Hi,
thorne <ego111@gmail.com> writes:
> On Mon, Sep 24, 2012 at 3:53 PM, thorne <ego111@gmail.com> wrote:
>> (defun render-one (file)
>> (with-temp-buffer
>> (insert-file file)
>> (org-export-as-html nil nil nil 'string t)))
>
> Well, I still don't know why it behaves the way I've described, but it
> works the way I want if instead of the above function, I use:
>
> (defun render-one (file)
> (save-excursion
> (let ((buffer (set-buffer (find-file file))))
> (setq rtn (org-export-as-html nil nil nil 'string t))
> (kill-buffer buffer)
> rtn)))
>
> -- using find-file and messing with the buffer stuff by hand, instead
> of using `with-temp-buffer' and `insert-file', which later strikes me
> as neater, and possibly faster (I am using it in batch to process
> multiple files) but the other way works, so that's fine. Thanks.
Just out of curiosity, did it work for you the way I suggested?
find-file will load the appropriate mode, hence no need for (org-mode)
in your latest function.
--
Bastien
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html'
2012-09-25 9:13 ` Bastien
@ 2012-09-26 7:28 ` thorne
0 siblings, 0 replies; 6+ messages in thread
From: thorne @ 2012-09-26 7:28 UTC (permalink / raw)
To: emacs-orgmode
In case anyone might be interested in this, here is what I think is a
minimal example. As I said, I am fine with it for my purposes, but
since the behaviour seems inconsistent (from my possibly limited
perspective) I thought I ought to at least specify as clearly as
possible what is going on:
First, with emacs -Q, and with a file called ~/tmp/foo.org
It's contents are only this:
#+BEGIN_SRC emacs-lisp :exports results :results html
"<>"
#+END_SRC
Now, slightly reformatted for clarity, M-x ielm --
*** Welcome to IELM *** Type (describe-mode) for help.
ELISP> (defun render-with-find-file (file)
(save-excursion
(let ((buffer (set-buffer (find-file file))))
(setq rtn (org-export-as-html nil nil nil 'string t))
(kill-buffer buffer)
rtn)))
==> render-with-find-file
ELISP> (defun render-with-temp-buffer (file)
(with-temp-buffer
(insert-file file)
(org-mode) ; doesn't actually seem to have any effect
(org-export-as-html nil nil nil 'string t)))
==> render-with-temp-buffer
ELISP> (render-with-find-file "~/tmp/foo.org")
==> #("<>\n\n" 0 2
(org-native-text t original-indentation 0 org-protected t
fontified nil)
2 3
(fontified nil)
3 4
(fontified nil))
ELISP> (render-with-temp-buffer "~/tmp/foo.org")
==> #("<pre class=\"example\">\n<>\n</pre>\n\n\n" 0 40
(fontified nil))
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-09-26 7:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-24 6:34 Emacs lisp code export difference between `org-export-region-as-html' and `org-export-as-html' thorne
2012-09-24 21:53 ` thorne
2012-09-25 1:24 ` Bastien
2012-09-25 6:05 ` thorne
2012-09-25 9:13 ` Bastien
2012-09-26 7:28 ` thorne
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).