12

For example, I got a demo to show a command and its output, and I want to insert them into an .org file like a source code snippet of C or something. I then want to be able to export the file to an HTML file, and have the block highlighted just like examples are in many books.

For example, I have

#+BEGIN_SRC shell
$ ls
dir1
dir2
file1
file2
...
or any other examples like this
...
#+END_SRC

but it cannot be converted to HTML: An error message that reads

shell-mode: Wrong type argument: processp, nil

shows up all the time. What mode should I use to replace shell, and if I should not use the #+BEGIN_SRC...#+END_SRC format, what should I use instead?

16

If you want to construct examples yourself (that's what I'm getting from your question, but correct me if I'm wrong), use an EXAMPLE block instead of a SRC block:

#+BEGIN_EXAMPLE
$ ls
dir1
dir2
file1
file2
...
#+END_EXAMPLE

When exporting to HTML, this block becomes:

<pre class="example">
$ ls
dir1
dir2
file1
file2
...
</pre>

As you can see, the contents of the exported block are exactly the same as the contents of the original EXAMPLE block.


If you actually want to run one or more commands to produce output dynamically and include both the commands and the results in your HTML document, you need to modify the SRC block to look like this:

#+BEGIN_SRC sh :exports both
ls
#+END_SRC

If the output of the ls command includes the directories and files you listed in your example (dir1, dir2, file1, file2), this will export to:

<div class="org-src-container">
  <pre class="src src-sh">
    ls
  </pre>
</div>

<table>
  <colgroup>
    <col class="left" />
  </colgroup>
  <tbody>
    <tr>
      <td class="left">dir1</td>
    </tr>
    <tr>
      <td class="left">dir2</td>
    </tr>
    <tr>
      <td class="left">file1</td>
    </tr>
    <tr>
      <td class="left">file2</td>
    </tr>
  </tbody>
</table>

As you can see, the code itself is wrapped in a code block, and the results are listed in a table.

Note that you will need to enable support for sh code blocks explicitly via:

(require 'ob-sh)
(org-babel-do-load-languages 'org-babel-load-languages '((sh . t)))

This is because by default Org Babel only enables support for Emacs Lisp code blocks (as explained here).

  • Thank you for the ob thing, I got two more problems, 1: is there any built-in shortcut to insert the pair of BEGIN_EXAMPLE, like <s then TAB to insert the BEGIN_EXAMPLE besides to define a snippet in yasnippet? 2: I got org-html-handle-links: Wrong type argument: stringp, nil error message after changing the BEGIN_EXAMPLE but nothing more, there must be something wrong about the link in my org file, there are a lot of them, how I can make org-export to show more detail such as line number that is wrong when exporting failed?? – CodyChan Nov 7 '14 at 9:16
  • Addressing your first question: Yes, there is, it's <e followed by TAB. See Easy Templates for a full list. – itsjeyd Nov 7 '14 at 9:20
  • As for your second question: I'm not sure I know what you mean. What link(s)? There aren't any links in your original example. As a general piece of advice, try to get a minimal example working first. Put the EXAMPLE block as shown in my answer into a new file by itself. Don't add anything else. Then try to export it and see what happens. If that works, gradually add more stuff and keep exporting as you do. If you run into an error at some point you will know that the last addition (or change) you made is causing it. – itsjeyd Nov 7 '14 at 9:28
  • The problem of my original post is solved by BEGIN_EXAMPLE. BEGIN_EXAMPLE error is located by the org-export itself, so I know it is the BEGIN_SRC issue, but there are a lot more in my original file, after org-export, only the org-html-handle-links: Wrong type argument: stringp, nil error message shows up and I don't where the exact position is. – CodyChan Nov 7 '14 at 9:42
  • @CodyChan I'm not following. If you want me to have a look at the contents of the file you are trying to export, add it to your question (you can remove it again later). – itsjeyd Nov 7 '14 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.