emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Interpreter/shell prompts when exporting code blocks?
@ 2013-07-26 14:14 Brett Viren
  2013-07-26 15:24 ` Eric Schulte
  2013-07-26 15:33 ` Rick Frankel
  0 siblings, 2 replies; 3+ messages in thread
From: Brett Viren @ 2013-07-26 14:14 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi organistas.

I'd like to have my executable code blocks get exported to HTML/LaTeX
with some prompt prefixed to each line of code but still let the blocks
themselves remain executable in their given language.  Is there already
a nice way to do this?

For example, if there was something like a "prompt" header to specify
what should get prefixed on export then something like...

#+prompt: $ 
#+BEGIN_SRC sh :results none :exports code
mkdir mymod
touch mymod/__init__.py
#+END_SRC

#+prompt: >>> :indent ...
#+BEGIN_SRC python :results none :exports code
import mymod
def myfun():
    mymod.something()
#+END_SRC

...would export something resembling:

$ mkdir mymod
$ touch mymod/__init__.py

>>> import mymod
>>> def myfun():
...     mymod.something()


For HTML export, some stylesheet magic which allows any cut-and-paste to
ignore the prefixed prompt would be icing on an already tasty cake.

-Brett.

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Interpreter/shell prompts when exporting code blocks?
  2013-07-26 14:14 Interpreter/shell prompts when exporting code blocks? Brett Viren
@ 2013-07-26 15:24 ` Eric Schulte
  2013-07-26 15:33 ` Rick Frankel
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2013-07-26 15:24 UTC (permalink / raw)
  To: Brett Viren; +Cc: emacs-orgmode

Brett Viren <bv@bnl.gov> writes:

> Hi organistas.
>
> I'd like to have my executable code blocks get exported to HTML/LaTeX
> with some prompt prefixed to each line of code but still let the blocks
> themselves remain executable in their given language.  Is there already
> a nice way to do this?
>
> For example, if there was something like a "prompt" header to specify
> what should get prefixed on export then something like...
>
> #+prompt: $ 
> #+BEGIN_SRC sh :results none :exports code
> mkdir mymod
> touch mymod/__init__.py
> #+END_SRC
>
> #+prompt: >>> :indent ...
> #+BEGIN_SRC python :results none :exports code
> import mymod
> def myfun():
>     mymod.something()
> #+END_SRC
>
> ...would export something resembling:
>
> $ mkdir mymod
> $ touch mymod/__init__.py
>
>>>> import mymod
>>>> def myfun():
> ...     mymod.something()
>
>
> For HTML export, some stylesheet magic which allows any cut-and-paste to
> ignore the prefixed prompt would be icing on an already tasty cake.
>
> -Brett.

I think the best solution here would be to apply your own custom CSS to
the page, or possibly to post-process the code blocks with a custom
export filter, see (info "(org)Advanced configuration").

Best,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

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

* Re: Interpreter/shell prompts when exporting code blocks?
  2013-07-26 14:14 Interpreter/shell prompts when exporting code blocks? Brett Viren
  2013-07-26 15:24 ` Eric Schulte
@ 2013-07-26 15:33 ` Rick Frankel
  1 sibling, 0 replies; 3+ messages in thread
From: Rick Frankel @ 2013-07-26 15:33 UTC (permalink / raw)
  To: Brett Viren; +Cc: emacs-orgmode

On 2013-07-26 10:14, Brett Viren wrote:
> I'd like to have my executable code blocks get exported to HTML/LaTeX
> with some prompt prefixed to each line of code but still let the blocks
> themselves remain executable in their given language.  Is there already
> a nice way to do this?
[snip]

Not exactly what you asked for, but how about using noweb references:

#+begin_src org
,* Prefix export
,#+name: sh-src
,#+BEGIN_SRC sh :results none :exports none
echo "foo"
echo "bar"
,#+END_SRC

,#+BEGIN_SRC sh :noweb yes :exports code :eval never
$ <<sh-src>>
,#+END_SRC

,#+name: python-src
,#+BEGIN_SRC python :exports none
import mymod
defun myfun():
mymod.foo()
,#+END_SRC

,#+BEGIN_SRC python :noweb yes :exports code :eval never
 >>>> <<python-src>>
#+END_SRC
#+end_src

which exports as (text export):

━━━━━━━━━━━━━━━
PREFIX EXPORT


Rick Frankel
━━━━━━━━━━━━━━━


╭────
│ $ echo "foo"
│ $ echo "bar"
╰────
╭────
│ >>>> import mymod
│ >>>> defun myfun():
│ >>>>     mymod.foo()
╰────

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

end of thread, other threads:[~2013-07-26 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-26 14:14 Interpreter/shell prompts when exporting code blocks? Brett Viren
2013-07-26 15:24 ` Eric Schulte
2013-07-26 15:33 ` Rick Frankel

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